函数指针数组 声明
方式1:直接声明
void fun0(u8 ucValue){}
void fun1(u8 ucValue){}
void fun2(u8 ucValue){}
void (*fun[])(u8 ucValue)=
{
fun0,
fun1,
fun2
};
如果要调用该函数指针 必须放到函数中执行 (* fun[0])(1);
直接在函数外存放,否则出错
提示
error: the size of an array must be greater than zero
方式2 用typedef 先声明新类型,再声明
typedef void (*fun1212)(u8 ucValue);
void fun0(u8 ucValue){}
void fun1(u8 ucValue){}
void fun2(u8 ucValue){}
fun1212 funx[10] =
{
fun0,
fun1,
fun2
};
void (*fun[])(u8 ucValue)=
{
fun0,
fun1,
fun2
};
同样如果要调用该函数指针 必须放到函数中执行
下面也是几个例子
void Num1_1(void){JumpMenu(30,1);WriteLcd();};
void Num1_2(void){JumpMenu(50,1);WriteLcd();};
void Num1_3(void){JumpMenu(60,1);WriteLcd();};
typedef void (*F_NumOperate)(unsigned char Value);
F_NumOperate f_numA;
typedef void (*F_FunA)(void);
F_FunA Fun_1[8]={Num1_1,Num1_2,Num1_3};
//测试赋值
void KKK (void)
{
Fun_1[0]=Num1_1;
}
typedef void F_FunB(void);
F_FunB * Fun_2[8];
//Fun_2[0]=Num1_2;
// =
// {
// Num1_1,
// Num1_2,
// Num1_3
// };
#if 0
F_FunB * pFun_ShortKey [4]=
{
OperateMain1_LastsPage,
OperateMain1_Sepical,
OperateMain1_MenuPage,
OperateMain1_NextPage
};
#endif
// F_FunB * pFun_DirectKey [4]= {};
// F_FunB * pFun_NumKey [10]= {};
//static void F_Num(void) * _apfTest[] ;
//变形3
// typedef void (*F_FunA)(unsigned char Index);
// F_FunA Fun_1[8]={Num1_1,Num1_2,Num1_3};
// //如何让 Num1_1 执行的时候 带上参数呢?
typedef struct // 事件函数表
{
uint32_t nSendInterval; // 事件发送间隔
void (* pfSendEvent)(TBMSCommControl *, uint32_t ); // 对应的事件函数
} TBMSCommSendEvent;
pfSendEvent = fun;
pfSendEvent ((TBMSCommControl *)&ggg,2)
用户244424 2011-3-16 14:15