083-struct-byval-arg.c (419B)
1 /* Pass struct by value as fn arg, return struct by value. 2 * CC.md §Declarations doesn't forbid; tcc.c uses it. */ 3 4 struct Pair { int a; int b; }; 5 6 int sum_pair(struct Pair p) { return p.a + p.b; } 7 8 int main(int argc, char **argv) { 9 struct Pair x = { 3, 7 }; 10 if (sum_pair(x) != 10) return 1; 11 /* Caller's struct must be unmodified by callee scope */ 12 if (x.a != 3 || x.b != 7) return 2; 13 return 0; 14 }