#define BUILD_BUG_OR_ZERO(e) (sizeof(struct{ int:-!!(e);})) #define ENSURE_EVEN_SIZE(e) BUILD_BUG_OR_ZERO((sizeof(e) % 2 == 1)) struct uneven{ char a,b,c; }; struct even{ char a,b,c,d; }; int main(){ ENSURE_EVEN_SIZE(struct even); /* compiler error: */ ENSURE_EVEN_SIZE(struct uneven); }
Standard input is empty
prog.c: In function ‘main’: prog.c:1:30: warning: statement with no effect [-Wunused-value] #define BUILD_BUG_OR_ZERO(e) (sizeof(struct{ int:-!!(e);})) ^ prog.c:2:29: note: in expansion of macro ‘BUILD_BUG_OR_ZERO’ #define ENSURE_EVEN_SIZE(e) BUILD_BUG_OR_ZERO((sizeof(e) % 2 == 1)) ^ prog.c:13:3: note: in expansion of macro ‘ENSURE_EVEN_SIZE’ ENSURE_EVEN_SIZE(struct even); ^ prog.c:15:27: error: negative width in bit-field ‘<anonymous>’ ENSURE_EVEN_SIZE(struct uneven); ^ prog.c:1:54: note: in definition of macro ‘BUILD_BUG_OR_ZERO’ #define BUILD_BUG_OR_ZERO(e) (sizeof(struct{ int:-!!(e);})) ^ prog.c:15:3: note: in expansion of macro ‘ENSURE_EVEN_SIZE’ ENSURE_EVEN_SIZE(struct uneven); ^ prog.c:1:30: warning: statement with no effect [-Wunused-value] #define BUILD_BUG_OR_ZERO(e) (sizeof(struct{ int:-!!(e);})) ^ prog.c:2:29: note: in expansion of macro ‘BUILD_BUG_OR_ZERO’ #define ENSURE_EVEN_SIZE(e) BUILD_BUG_OR_ZERO((sizeof(e) % 2 == 1)) ^ prog.c:15:3: note: in expansion of macro ‘ENSURE_EVEN_SIZE’ ENSURE_EVEN_SIZE(struct uneven); ^ prog.c:16:1: warning: control reaches end of non-void function [-Wreturn-type] } ^
Standard output is empty