2 * some testcases to check sanity of the offsetof implementation
3 * especially the __builtin_offsetof implementation
31 union bla abla_arr
[2];
34 typedef struct st st_t
;
35 typedef union bla bla_t
;
37 #define check(type, element) \
39 union { long bits; type *ptr; } nul; nul.bits = 0; \
40 x = (int) &(nul.ptr->element); \
41 y = offsetof (type, element); \
50 check (struct st
, first
);
51 #ifndef __SDCC_pdk14 // Lack of memory
54 check (struct st
, a
[9]);
56 check (struct st
, s
.x
);
57 check (struct st
, s
.ta
.t
);
58 check (struct st
, s
.fil
);
59 check (struct st
, s
.fil
[1]);
60 check (struct st
, arr
);
61 check (struct st
, arr
[1]);
62 check (struct st
, arr
[1].x
);
63 check (struct st
, arr
[1].fil
);
64 check (struct st
, arr
[1].fil
[1]);
65 check (struct st
, abla
);
66 check (struct st
, abla
.b
);
67 check (struct st
, abla_arr
);
68 check (struct st
, abla_arr
[1]);
69 check (struct st
, abla_arr
[1].b
);
70 check (struct st
, abla_arr
[1].ax
);
71 check (struct st
, abla_arr
[1].ax
.fil
);
72 check (struct st
, abla_arr
[1].ax
.fil
[1]);
75 z
= 7; check (struct st
, a
[z
*3+1]);
76 z
= 3; check (struct st
, arr
[z
].x
);
78 check (st_t
, arr
[1].fil
[1]);
81 ASSERT (0 == offsetof (union bla
, b
));
82 ASSERT (0 == offsetof (bla_t
, b
));