- 论坛徽章:
- 0
|
想把函数的指针存下来, 貌似C不支持在main外边掉用函数或对变量赋值...杯具
macroideal 发表于 2011-03-26 16:22 ![]() - #include <stdio.h>
- #include <stdlib.h>
- typedef void(*proc_type)();
- int store_addr(long add)
- {
- ((proc_type)add)();
- }
- int store_addr_ex(proc_type func)
- {
- if (func)
- func();
-
- return 1;
- }
- void test_function()
- {
- printf("this is a big test\n");
-
- }
- void test_function_ex()
- {
- printf("this is a big test ex\n");
-
- }
- static proc_type my_proc_list[] = {test_function, test_function_ex, 0};
- int main(int argc, char* argv[])
- {
- int i;
- for (i = 0; ; ++i) {
- if (!my_proc_list[i]) break;
-
- my_proc_list[i]();
- }
- store_addr(test_function ) ;
- store_addr_ex(test_function) ;
-
- }
复制代码 |
|