Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Jul 2010 21:55:10 +0200
From:      Nathan Whitehorn <nwhitehorn@freebsd.org>
To:        Kostik Belousov <kostikbel@gmail.com>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, Stefan Farfeleder <stefanf@freebsd.org>, src-committers@freebsd.org, Bruce Evans <brde@optusnet.com.au>
Subject:   Re: svn commit: r210451 - head/sys/sys
Message-ID:  <4C4C969E.1060602@freebsd.org>
In-Reply-To: <20100725181255.GB22295@deviant.kiev.zoral.com.ua>
References:  <201007241814.o6OIEY4K099556@svn.freebsd.org> <20100724183732.GA1715@mole.fafoe.narf.at> <20100726013202.G11808@delplex.bde.org> <20100725181255.GB22295@deviant.kiev.zoral.com.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C4C969E.1060602>