Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Apr 2015 22:40:46 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Bruce Evans <brde@optusnet.com.au>, David Chisnall <theraven@freebsd.org>,  John Baldwin <jhb@freebsd.org>, Justin Hibbits <jhibbits@freebsd.org>,  src-committers@freebsd.org, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r281721 - head/sys/sys
Message-ID:  <20150421222539.J2985@besplex.bde.org>
In-Reply-To: <20150421095900.GL2390@kib.kiev.ua>
References:  <201504190033.t3J0XMDX041769@svn.freebsd.org> <476583045.Qcb6O2DFtY@ralph.baldwin.cx> <20150421020808.D10623@besplex.bde.org> <785A553E-317E-4C80-83A0-567C80697ED8@FreeBSD.org> <20150421184157.Y2048@besplex.bde.org> <20150421095900.GL2390@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 21 Apr 2015, Konstantin Belousov wrote:

> On Tue, Apr 21, 2015 at 07:32:30PM +1000, Bruce Evans wrote:
>> On Tue, 21 Apr 2015, David Chisnall wrote:
>>
>>> On 20 Apr 2015, at 17:19, Bruce Evans <brde@optusnet.com.au> wrote:
>>>>
>>>> Enums should never be used in ABIs, since their size can be anything
>>>> large enough.
>>>
>>> The rules for the size of enums also differ between C and C++, though clang (and, I think, gcc) support an attribute for specifying the enum type.
>>>
>>>> They also cause namespace problems.  The whole enum declaration must
>>>> be exposed in any header that uses an enum type.
>>>
>>> Both C and C++ permit forward declarations of enums for use in function prototypes and so on, e.g.:
>>>
>>> enum foo;
>>> void
>>> bar(enum foo);
>>
>> No, they cannot do this since the size may depend on the internals of the
>> enum:
>>
>> TendDRA-5.0.0:
>> "z.c", line 1: Error:
>>    [ISO C90 6.5.2.3]: Can't declare the enumeration 'enum foo'.
>>
> This is not true for C.  The i386 ABI specification, from year _1997_,
> states that enum must be 4-bytes unsigned entity, 4-bytes aligned.  See page
> 28 of abi386-4.pdf.

That is only the i386 implementation of C.  Good enough for ABI portability.

Is it really so broken as to specify unsigned?  enum values have type int,
so unsigned cannot represent all of them.

Unrepresentable enums are detected in all compilers I tested, but the
error handling is broken except in gcc:

clang-current:
   z.c:1:29: warning: overflow in enumeration value
   enum foo { xx = 0x7fffffff, yy };
                             ^
   1 warning generated.

   gcc4.2.1:
   z.c:1: error: overflow in enumeration values

TenDRA-5.0.0:
   trans:/tmp/tccljzRYO/_tcc.t: internal error: constant out of range

TendDRA also suffers from the C90 design error of not allowing a comma
after yy.  It detects this and handles it perfectly brokenly to C90
spec:

   "z.c", line 1: Error:
     [Syntax]: Extra comma at end of list.

Bruce



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