summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-05-22 09:07:35 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commitf313a958abd17a56a09ae76dff59c75dcfdf233a (patch)
tree477641602b91d47b5b134f45f7520fecbd0ed1d8 /src/test
parentc64e9548c4c1b3958601df4929e812d226809f8c (diff)
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.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-sizeof.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/test/test-sizeof.c b/src/test/test-sizeof.c
index 103c96955..2f369ef25 100644
--- a/src/test/test-sizeof.c
+++ b/src/test/test-sizeof.c
@@ -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) {
@@ -59,6 +64,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;
}