This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Warn about bitfields larger than union
- From: Jon Grant <jg at jguk dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 30 Oct 2011 18:12:25 +0000
- Subject: 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