Re: help with enum

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux