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]

Re: Warn about bitfields larger than union


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];


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