define##/#サンプル
[root@A0-F3-C1-17-02-A8 north]# cat sys_fun.c
id:0 write0:10-5=5
id:1 write1:10+5=15
id:2 write2:10*5=50
#include <stdio.h> typedef struct { char name[20]; void (*fun)(); } sys_fun; void write0(int id, int val1, int val2); void write1(int id, int val1, int val2); void write2(int id, int val1, int val2); #define fun_name(i) "write"#i #define fun_call(i) write##i sys_fun entry[] = {{fun_name(0), fun_call(0)}, {fun_name(1), fun_call(1)}, {fun_name(2), fun_call(2)}}; void entry_fun_call(int id, int val1, int val2); void main() { entry_fun_call(0, 10, 5); entry_fun_call(1, 10, 5); entry_fun_call(2, 10, 5); } void entry_fun_call(int id, int val1, int val2) { entry[id].fun(id, val1, val2); } void write0(int id, int val1, int val2) { printf("id:%d %s:%d-%d=%d\n", id, entry[id].name, val1, val2, val1 - val2); } void write1(int id, int val1, int val2) { printf("id:%d %s:%d+%d=%d\n", id, entry[id].name, val1, val2, val1 + val2); } void write2(int id, int val1, int val2) { printf("id:%d %s:%d*%d=%d\n", id, entry[id].name, val1, val2, val1 * val2); }[root@54-27-1E-46-02-66 north]# ./sys_fun.out
id:0 write0:10-5=5
id:1 write1:10+5=15
id:2 write2:10*5=50