为什么会这样:
#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);
}
在C中打印4 8 8
,在C++中打印8 8 8
(在一个带有4字节的平台上)
我的印象是,UINT64_MAX
赋值将强制所有枚举常量至少为64位,但在普通C中,en_e_foo
保持为32位.
这种差异的原因是什么?