SOLVED (was: Re: How to avoid "the address of 'foo' will never be NULL" warning inside macros?)

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

 



Hi,

I had the following warning and now I found a simple workaround:

On Thu, Jun 9, 2011 at 10:15 AM, Steffen Dettmer
<steffen.dettmer@xxxxxxxxxxxxxx> wrote:
> Hi,
>
> we implement some features either as functions or macros (if
> small). One of the used compilers is gcc. With gcc-4.6.0 we get
> new warnings.
>
> With macros, we for example have:
>
>  #define fooGetFooPtr(bar) \
>     (const uint8*)(((bar) != NULL ? (bar)->foo_ : (const uint8*)bar))
>
> when used as:
>
>  struct bar_s bar;
>  ptr *p = fooGetFooPtr(&bar);
>
> leading to:
>
>  error: the comparison will always evaluate as 'true' for the
>  address of 'bar' will never be NULL [-Werror=address]

casting the argument to "void*" before the check helps:

#define fooGetFooPtr(bar) \
   (const uint8*)((((void*)bar) != NULL ? (bar)->foo_ : (const uint8*)bar))

just in case someone searches through the mail archives :-)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux