Warn about bitfields larger than union

Jon Grant jg@jguk.org
Sun Oct 30 18:12:00 GMT 2011


Hello

I've uploaded a simple C program which shows my query:

http://pastebin.com/BQmG0m3g

Is there a way for GCC to warn when union size is exceeded by a bit-field?


Essentially a union of a type, and a bit-field. The bit-field is larger 
than the first member of the union. This means that the struct is larger 
than the uint8_t expected, it compiles as 2 bytes large. Output below.


jon@laptop:~$ gcc -Wall -o union union.c
jon@laptop:~$ ./union
sizeof(test_t): 4
t: 0x0x92f0008
reg0: 0x0x92f0008
reg1: 0x0x92f000a
sizeof(t): 4


Thank you for any feedback

Please keep my email address in any replies.

Best regards, Jon



More information about the Gcc-help mailing list