C语言根据函数名调用对应的函数

通过函数指针定义,调用时加上参数

struct Command {
const char *name;
const char *desc;
// return -1 to force monitor to exit
int (*func)(int argc, char** argv, struct Trapframe* tf);
};

static struct Command commands[] = {
{ "help", "Display this list of commands", mon_help },
{ "kerninfo", "Display information about the kernel", mon_kerninfo },
{ "backtrace", "Display the current stack trace", mon_backtrace },
};

if (strcmp(argv[0], commands[i].name) == 0)
return commands[i].func(argc, argv, tf);

上一篇:css中的宽度


下一篇:Class.getResource和ClassLoader.getResource的区别分析