This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Size of enumâ
On Sun, Feb 5, 2012 at 12:58 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> 2012/2/5 David Brown :
>>
>> Enum types in C++ can be any integer type big enough to cover the required
>> range. ?I think most C++ compilers use the smallest integer type that covers
>> the range.
>
> With the three C++ compilers I tried enums are int-sized for
> compatiblity reasons, so that enums declared in a header file included
> by C code and C++ code will agree on the type layout.
A decade ago I dealt with at least one platform where that was not the
case (meaning that using enums had to be disallowed in header files
that defined interfaces between C and C++ code).
I don't recall whether C allows enums types to vary in size, but in
practice I've not noticed a C compiler that did.