X-Git-Url: https://pd.if.org/git/?p=lice;a=blobdiff_plain;f=tests%2Foffsetof.c;fp=tests%2Foffsetof.c;h=bbc4ee09e7b00edeef0ccf5af35fa9813e96b5fd;hp=0000000000000000000000000000000000000000;hb=946bdbe1d5dd89ab671391fbe429a1c2c48ecaa7;hpb=f1abb26903687c7967cf37c3f6c830051bdeb371 diff --git a/tests/offsetof.c b/tests/offsetof.c new file mode 100644 index 0000000..bbc4ee0 --- /dev/null +++ b/tests/offsetof.c @@ -0,0 +1,27 @@ +// offsetof + +#include + +struct test { + int a; // 0 + int b; // 4 + int c; // 8 + char d; // 12 + short e; // 14 + int f; // 16 +}; + +int main(void) { + expecti(offsetof(struct test, a), 0); + expecti(offsetof(struct test, b), 4); + expecti(offsetof(struct test, c), 8); + expecti(offsetof(struct test, d), 12); + expecti(offsetof(struct test, e), 14); + expecti(offsetof(struct test, f), 16); + + // it should also be a valid integer constant expression + int a[offsetof(struct test, b)]; + expecti(sizeof(a), sizeof(int) * 4); + + return 0; +}