18 #define offsetof(TYPE, MEMB) ((char*) (&((TYPE *)0)->MEMB) - (char*) 0)
20 int main(int argc, char **argv) {
21 struct bf mybf = { 0xffffffff, 4097, 65537, 5, 0xff, 4.5, 257 };
24 dumpMem(&mybf, sizeof mybf);
25 printf("sizeof mybf %d\n", sizeof mybf);
26 printf("offset a = %d\n", offsetof(struct bf, a));
27 printf("offset c = %d\n", offsetof(struct bf, c));
28 printf("offset d = %d\n", offsetof(struct bf, d));
30 printf("int a (expected -1): %d\n", mybf.a);
31 printf("unsigned x:13 (expected 4097): %u\n", mybf.x);
32 printf("unsigned y:17 (expected 65537): %u\n", mybf.y);
33 printf("unsigned y:3 (expected 5): %u\n", mybf.z);
34 printf("char c (expected ff): %x\n", mybf.c);
35 printf("double d (expected 4.5): %.1f\n", mybf.d);
36 printf("unsigned w:9 (expected 257): %u\n", mybf.w);