64,282
社区成员
发帖
与我相关
我的任务
分享
"main.c" 32L, 499C written
[User:root Time:13:55:26 Path:/home/liangdong/c]$ gcc -o main main.c
[User:root Time:13:55:27 Path:/home/liangdong/c]$ ./main
func1
func2
[User:root Time:13:55:28 Path:/home/liangdong/c]$ cat main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef void (*ptr_func)();
typedef ptr_func *arr_ptr_func;
void test_func1() {
printf("func1\n");
}
void test_func2() {
printf("func2\n");
}
int main(int argc, char* argv[]) {
arr_ptr_func map[65536];
map[5] = (arr_ptr_func)malloc(sizeof(ptr_func) * 3);
map[5][0] = test_func1;
map[5][1] = test_func2;
map[5][2] = NULL;
int ndx = 5;
arr_ptr_func ptr = map[5];
while (*ptr != NULL) {
(*ptr)();
++ ptr;
}
return 0;
}