question on GCC compiler and enum sizes

Eljay Love-Jensen
Wed Feb 23 12:27:00 GMT 2005

Hi Kevin,

One compiler I used (back on the Amiga) had this kind of construct:

char enum Foo_t { one, two three } foo;
int enum Bar_t { uno, dos, tres } bar;
unsigned long enum Quux_t { un, deux, trois } quux;

(I may have gotten the syntax reversed.  It's been a long time.)

But, alas, this is not standard C/C++.

According to standard C (C89) and C++, enums are int.  An int being the 
platform architecture's natural word size.

So I believe the problem is twofold:
1. it'd be nice for C/C++ to qualify enum sizes other than int -- c'est la vie
2. the other compiler's non-standard / non-compliant extension is causing 
you grief -- disable that extension (likewise, don't use GCC's -fshort-enums)

For C++, you can fix the problem by moving away from enum.  But I presume 
you are working in C, not C++.

In C (C89), you can use #define.  Maybe C99 has a more elegant solution 
that isn't pre-processor (ick ick) based.


More information about the Gcc-help mailing list