test-sizeof: show that a small 64 field is not enough to force the enum to be 64 bits
On both 32 and 64 bits, the result is: enum Enum → 32 bits, unsigned enum BigEnum → 32 bits, unsigned enum BigEnum2 → 64 bits, unsigned big_enum2_pos → 4 big_enum2_neg → 8 The last two lines show that even if the enum is 64 bit, and the field of an enum is defined with UINT64_C(), the field can still be smaller.
This commit is contained in:
parent
930362ab26
commit
994282d2de
|
@ -26,7 +26,12 @@ enum Enum {
|
|||
};
|
||||
|
||||
enum BigEnum {
|
||||
big_enum_value = UINT64_C(-1),
|
||||
big_enum_value = UINT64_C(1),
|
||||
};
|
||||
|
||||
enum BigEnum2 {
|
||||
big_enum2_pos = UINT64_C(1),
|
||||
big_enum2_neg = UINT64_C(-1),
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
|
@ -55,6 +60,10 @@ int main(void) {
|
|||
|
||||
info(enum Enum);
|
||||
info(enum BigEnum);
|
||||
info(enum BigEnum2);
|
||||
assert_cc(sizeof(enum BigEnum2) == 8);
|
||||
printf("big_enum2_pos → %zu\n", sizeof(big_enum2_pos));
|
||||
printf("big_enum2_neg → %zu\n", sizeof(big_enum2_neg));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue