[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Warnings in mingw64 builds on master

From: Paul Eggert
Subject: Re: Warnings in mingw64 builds on master
Date: Sun, 16 Aug 2020 21:21:36 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 8/16/20 8:39 AM, Eli Zaretskii wrote:
the warning it emits has nothing to
do with correctness of the code.

I'm not sure I follow. Although it's true that adding __attribute__ ((malloc)) does not turn formerly-incorrect code into correct code, the same thing is true of other function attributes like _Noreturn. But that doesn't mean we shouldn't use function attributes.

The main reason I like __attribute__ ((malloc)) has little to do with improving performance (is that what you meant by "improving the code"?); it has to do with understanding the code and using that understanding to avoid and/or fix bugs. When I see code like this:

   char *p = xmalloc (s);
   memcpy (p, q, r);

I mentally have to answer questions like "is r <= s?" because otherwise the behavior is undefined. But I do not have to mentally answer questions like "are *p and *q aliases?" - even though the behavior of memcpy would be undefined if they were aliases - because malloc has __attribute__ ((malloc)) and this means *p cannot alias with anything else.

This is not simply a matter of memcpy vs memmove. In C one must constantly worry about aliasing. These worries are lessened with __attribute__ ((malloc)), so the attribute is typically a win.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]