What is the size of an enum in C?
Taken from the current C Standard (C99): http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf
22.214.171.124 Enumeration specifiers
The expression that defines the value of an enumeration constant shall be an integer constant expression that has a value representable as an int.
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.
Not that compilers are any good at following the standard, but essentially: If your enum holds anything else than an int, you're in deep "unsupported behavior that may come back biting you in a year or two" territory.
I'm creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read somewhere that (at least in GCC) the compiler can make the enum any width they need to be to hold their values. So, is it possible to have an enum that is 64 bits wide?
Size of enums in bytes of different compilers
In both C and C++ an enum will have a size such that all the values can be represented and be compatible with an integer type. Different compilers may use different algorithm to choose the type (if it is not specified by another standard such a clearly defined ABI). (C++11 allows to specify the underlying type with a new syntax)
C language enumeration datatype?
This statement is from C99 126.96.36.199p4
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined,108) but shall be capable of representing the values of all the members of the enumeration.
108) An implementation may delay the choice of which integer type until all enumeration constants have been seen.
This allows the compiler to make what it believes to be the best choice for a particular enumeration. An enumeration is probably not the best choice to use in a binary message passed between machines. But, you can use an integer type, and cast back to the enumerated type.