我正在尝试为初始化系统编写函数,同时插入函数指针以使用系统索引和值进行系统触发处理
那么我如何访问变量index
和val
在System_Init
功能
typedef void (*System_Handler)(unsigned int short indx, char val);
void System_Init(Switch_Handler sw_hdl)
{
unsigned short int test;
test = indx;
/* Need to access variables indx and val Here . How can we do ?*/
}
最佳答案
函数指针不与一组函数参数捆绑在一起。 您必须单独提供参数,通常是将它们与函数指针一起传递:
typedef void (*System_Handler)(unsigned int short indx, char val);
void System_Init(System_Handler sw_hdl, unsigned short indx, char val)
{
unsigned short int test;
test = indx;
//...
sw_hdl(indx,val);
}
关于c - 函数指针处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56258698/