Segher Boessenkool wrote on 04/23/2019 06:02 PM:
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.
Ok, now using -1 for ~0u, and CHAR_BIT for 8.
But what's your objection regarding sizeof?
Thx