Suppressing GCC warning locally inside a macro

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

 



Hi,
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; \
  })

The -Woverflow warning happens because the struct member field is
a small bitfield, for example "unsigned x : 5;".

Of course globally it works by using the following construct:

  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Woverflow"
    f();   // wherein the macro is called/used
  #pragma GCC diagnostic pop

But I would like to have this warning suppressed locally inside the macro itself.
Is it somehow possible?

Thx



[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