]> pd.if.org Git - lice/blob - tests/offsetof.c
bbc4ee09e7b00edeef0ccf5af35fa9813e96b5fd
[lice] / tests / offsetof.c
1 // offsetof
2
3 #include <stddef.h>
4
5 struct test {
6     int   a; // 0
7     int   b; // 4
8     int   c; // 8
9     char  d; // 12
10     short e; // 14
11     int   f; // 16
12 };
13
14 int main(void) {
15     expecti(offsetof(struct test, a), 0);
16     expecti(offsetof(struct test, b), 4);
17     expecti(offsetof(struct test, c), 8);
18     expecti(offsetof(struct test, d), 12);
19     expecti(offsetof(struct test, e), 14);
20     expecti(offsetof(struct test, f), 16);
21
22     // it should also be a valid integer constant expression
23     int a[offsetof(struct test, b)];
24     expecti(sizeof(a), sizeof(int) * 4);
25
26     return 0;
27 }