Why does this:
#include <stdio.h>
#include <limits.h>
#include <inttypes.h>
int main() {
enum en_e {
en_e_foo,
en_e_bar = UINT64_MAX,
};
enum en_e e = en_e_foo;
printf("%zu\n", sizeof en_e_foo);
printf("%zu\n", sizeof en_e_bar);
printf("%zu\n", sizeof e);
}
print 4 8 8
in C and 8 8 8
in C++ (on a platform with 4 byte ints)?
I was under the impression that the UINT64_MAX
assignment would force all the enumerations constants to at least 64 bits, but en_e_foo
remains at 32 in plain C.
What is the rationale for the discrepancy?