017-apply.c (692B)
1 /* tests/cc-e2e/17-apply.c — fn-ptr param + struct-ptr param + member access via ->. 2 * Depends on the same g_pt2 designated-init data the 12-struct-ptr fixture uses. 3 * Split from 01-kitchen-sink. */ 4 5 typedef int (*op2_t)(int, int); 6 int op_add(int a, int b) { return a + b; } 7 int op_mul(int a, int b) { return a * b; } 8 9 struct Point { int x; int y; }; 10 struct Point g_pt = { 100, 200 }; 11 struct Point g_pt2 = { .y = 5, .x = 7 }; 12 13 int apply2(op2_t f, struct Point *p) { return f(p->x, p->y); } 14 15 int test_apply(void) { 16 return apply2(op_add, &g_pt) + apply2(op_mul, &g_pt2); /* 300 + 35 = 335 */ 17 } 18 19 int main(int argc, char **argv) { 20 if (test_apply() != 335) return 1; 21 return 0; 22 }