功能指针处理程序

时间:2019-05-22 14:03:36

标签: c

我试图为初始化系统编写函数,同时为系统触发的插入系统指针和值的函数插入函数指针 因此,如何在index函数

中访问变量valSystem_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 ?*/
}

1 个答案:

答案 0 :(得分:3)

函数指针不与一组函数参数捆绑在一起。 您必须分别提供参数,通常是将它们与函数指针一起传递:

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);
}