help with enum
Eljay Love-Jensen
eljay@adobe.com
Wed Jun 22 16:29:00 GMT 2005
Hi Raman,
An enum is supposed to be set to an int or an unsigned int (i.e., a machine word).
Some compilers take liberties, and will resize an enum to a {signed|unsigned|nonsigned} char size, or {signed|unsigned} short int size, or even {signed|unsigned} long int size.
Other compilers, have an extension to specify the storage size, such as "enum short Foo { one, two, three };" ... but that is definitely non-portable.
GCC has the -fshort-enums flag, which gives a little extra control over enum sizes. But it has a sweeping effect.
But by and large, and if you value C/C++ portability, presume that all enums are int or unsigned int sized (machine word sized).
In C++, if that is unacceptable, consider using const values. That will give you more specific and portable control over the actual size of the enumerations.
HTH,
--Eljay
More information about the Gcc-help
mailing list