为什么这样做:
#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);
}
4 8 8
用C和8 8 8
C ++(在具有4字节整数的平台上)打印?
我的印象是,UINT64_MAX
赋值将强制所有枚举常量至少为64位,但en_e_foo
在纯C中仍为32位。
差异的理由是什么?