- 论坛徽章:
- 0
|
函数指针变量的类型转换
原帖由 "win_hate" 发表:
我不是大侠,对这些东西恰好略知一二,看了你的贴子后大惑不解:
1. __cdecl 是 c 的默认函数调用方式,为何要转换成这种形式?除非你在编译的时候指定了不同的调用方式,而你想覆盖它。
2. #define __cdecl ?.........
1.__cdecl是是 c 的默认函数调用方式,而我这个是在solaris下forte c没有,所以我定义了一个。也可以不用它:
- pf2 = (int *(*)(int *))alter[i].pfun;
复制代码
2.那个代码只是示范,block是在其它地方被赋值的,我的表达能力并不好请看我的范例:
- .h
- typedef struct alter_fun
- {
- void *pfun;/*载入函数*/
- int nfuntype;
- }ALTER_FUN;
- int *FunctionPoint1(int *ival);
- void FunctionPoint2();
- .c
- ALTER_FUN alter[] =
- {
- {FunctionPoint,1},
- {FunctionPoint2,2},
- {NULL,0}
- };
- {
- i = 0;
- while(alter[i].pfun)
- {
- switch(alter[i].nfuntype)
- {
- case 1:
- //用类型1函数指针来转换alter[i].pfun,并执行
- break;
- case 2:
- //用类型2函数指针来转换alter[i].pfun,并执行
- break;
- .
- .
- .
- }
- i ++;
- }
- }
复制代码 |
|