This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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@googlemail.com> 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]