016-fn-ptr.c (492B)
1 /* tests/cc-e2e/16-fn-ptr.c — function-pointer global table + indirect call. 2 * Split from 01-kitchen-sink. */ 3 4 typedef int (*op2_t)(int, int); 5 int op_add(int a, int b) { return a + b; } 6 int op_mul(int a, int b) { return a * b; } 7 op2_t g_ops[2] = { op_add, op_mul }; 8 9 int test_fn_ptr(void) { 10 op2_t add = g_ops[0]; 11 op2_t mul = g_ops[1]; 12 return add(3, 4) + mul(5, 6); /* 7 + 30 = 37 */ 13 } 14 15 int main(int argc, char **argv) { 16 if (test_fn_ptr() != 37) return 1; 17 return 0; 18 }