This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Warn about bitfields larger than union


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]