public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* SOLVED (was: Re: How to avoid "the address of 'foo' will never be NULL" warning inside macros?)
@ 2011-09-09 14:03 Steffen Dettmer
  0 siblings, 0 replies; only message in thread
From: Steffen Dettmer @ 2011-09-09 14:03 UTC (permalink / raw)
  To: gcc-help

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 :-)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-09-09 14:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-09 14:03 SOLVED (was: Re: How to avoid "the address of 'foo' will never be NULL" warning inside macros?) Steffen Dettmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).