This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Warn about bitfields larger than union
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "Kevin P. Fleming" <kpfleming at digium dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 31 Oct 2011 16:09:01 +0000
- Subject: Re: Warn about bitfields larger than union
- References: <4EAD9389.9070604@jguk.org> <4EAEBB9C.5070207@digium.com>
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];