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 <b...@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
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"