typeof and bitfields

Matt Austern austern@apple.com
Fri Jan 14 00:19:00 GMT 2005


On Jan 13, 2005, at 3:58 PM, Andrew Pinski wrote:

>
> On Jan 13, 2005, at 6:56 PM, Matt Austern wrote:
>
>> This was obviously a deliberate change.  However, I don't see any 
>> mention about it in the part of the manual that documents typeof.  I 
>> also can't guess why this should be different in C and in C++, or 
>> what the rationale for the change might have been in the first place. 
>>  Sure, applying sizeof or alignof to a bit-field makes no sense.  But 
>> typeof?  X::n has a perfectly good type, as the C++ compiler 
>> understands.
>
> The type of a bit-field is no longer the under lying type.  But the
> correct type which is required by the C standard.

Sorry, I don't understand how that answers my question.  As I read the 
C standard (6.7.2.1), it's quite clear that struct members declared as 
bit-fields still have types.  In
struct X { int n : 1 };
the type of the field "n" is int.  The C standard makes it quite clear 
that bit-fields can have types int, unsigned int, _Bool, and possibly 
other types.

So given that "n" has a type, what's the rationale for saying that 
users aren't allowed to look at that type using typeof?  The C++ 
compiler knows that the type of that field is "int", and I can't think 
of any reason why the C compiler shouldn't know that too.

			--Matt



More information about the Gcc mailing list