svn commit: r210451 - head/sys/sys

Nathan Whitehorn nwhitehorn at freebsd.org
Sun Jul 25 19:55:15 UTC 2010


On 07/25/10 20:12, Kostik Belousov wrote:
> On Mon, Jul 26, 2010 at 01:36:07AM +1000, Bruce Evans wrote:
>    
>> On Sat, 24 Jul 2010, Stefan Farfeleder wrote:
>>
>>      
>>> declaring enums like this is not standard C code (seems to be a GCC
>>> extension). I don't think we should use this feature in our headers.
>>>        
>> This is unfortunate.  This is because the size of an enum variable
>> depends on its complete declaration.  This is an error unconditionaly
>> with TenDRA.  It takes -pedantic to get a warning from gcc.
>>      
> I looked at the C99, and indeed, there is an explicit sentence
> "A type specifier of the form enum identifier without an enumerator list
> shall only appear after the type it specifies is complete."
>
> I fully agree with Bruce that this is unfortunate, or rather, makes
> enum tag declaration completely unuseful. gcc extension greatly simplifies
> dealing with the headers pollution.
>
> On the other hand, I disagree with the statement that the size of the
> enum variable depends on the full declaration. It seems that C99
> defines values of the enum to by of type int, and both i386 and
> amd64 ABIs define enums as represented by 4-byte integers.
> Yes, I am aware that C++ allows the enum to be assigned the
> the shortest arithmetic type that can represent all enum values.
>    

This is not actually true. Try adding a value that requires a 64-bit int 
to your enum -- it will become 8 bytes. Also, the signedness of the type 
depends on the values in the enumeration.
-Nathan


More information about the svn-src-head mailing list