012-struct-ptr.c (786B)
1 /* tests/cc-e2e/12-struct-ptr.c — struct passed by pointer + global struct 2 * with positional and designated initializers. 3 * 4 * Split from 01-kitchen-sink. Exercises the out-of-order designated init 5 * (.y = 5, .x = 7) which the global initializer code currently emits as 6 * an oversized data section instead of overwriting at absolute offsets. 7 */ 8 9 struct Point { int x; int y; }; 10 struct Point g_pt = { 100, 200 }; /* positional */ 11 struct Point g_pt2 = { .y = 5, .x = 7 }; /* designated, out-of-order */ 12 13 int f_struct_arg(struct Point *p) { return p->x + p->y; } 14 15 int test_struct_ptr(void) { 16 return f_struct_arg(&g_pt) + g_pt2.x + g_pt2.y; /* 300 + 7 + 5 = 312 */ 17 } 18 19 int main(int argc, char **argv) { 20 if (test_struct_ptr() != 312) return 1; 21 return 0; 22 }