Re: Suppressing GCC warning locally inside a macro

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

 



On Mon, Apr 22, 2019 at 11:11:47PM +0200, U.Mutlu wrote:
> is there a way to suppress a gcc compiler warning locally inside a macro 
> code?
> 
> #include <stddef.h>    // size_t
> #include <strings.h>   // ffs()
> 
> #define bitsizeof(type, member) \
>   ({ type t; \
>      t.member = ~0u;  /* compiler warning -Woverflow happens */ \
>      const size_t rc = ffs(t.member + 1); \
>      !rc ? sizeof(unsigned) * 8 : rc - 1; \
>   })

~0U does not work correctly for types bigger than int (but neither will
ffs, or that sizeof, and that 8 is not very portable either).

If you write -1 instead, everything just works.


Segher



[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