Putting the OP back in the To field ... On 31 October 2011 16:09, Jonathan Wakely wrote: > On 31 October 2011 15:15, Kevin P. Fleming wrote: >> On 10/30/2011 01:12 PM, Jon Grant wrote: >>> >>> 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? >> >> The 'union size' is determined from the largest member of the union. > > Indeed, I don't see how the compiler could know that you didn't mean > to make the union larger than the first member. > > If you want to put checks in for that, use a static assertions of some kind: > > char static_assert[(sizeof(REG0) == sizeof(REG0.reg8bit))-1]; >