1 2typedef __SIZE_TYPE__ Size_t; 3 4#if __SIZEOF_LONG__ < __SIZEOF_POINTER__ 5#define bufsize ((1LL << (8 * sizeof(Size_t) - 2))-256) 6#else 7#define bufsize ((1L << (8 * sizeof(Size_t) - 2))-256) 8#endif 9 10struct huge_struct 11{ 12 short buf[bufsize]; 13 int a; 14 int b; 15 int c; 16 int d; 17}; 18 19union huge_union 20{ 21 int a; 22 char buf[bufsize]; 23}; 24 25Size_t union_size() 26{ 27 return sizeof(union huge_union); 28} 29 30Size_t struct_size() 31{ 32 return sizeof(struct huge_struct); 33} 34 35Size_t struct_a_offset() 36{ 37 return (Size_t)(&((struct huge_struct *) 0)->a); 38} 39 40int main() 41{ 42 /* Check the exact sizeof value. bufsize is aligned on 256b. */ 43 if (union_size() != sizeof(char) * bufsize) 44 abort(); 45 46 if (struct_size() != sizeof(short) * bufsize + 4*sizeof(int)) 47 abort(); 48 49 if (struct_a_offset() < sizeof(short) * bufsize) 50 abort(); 51 52 return 0; 53} 54 55