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