【发布时间】:2015-09-07 11:01:33
【问题描述】:
我正在尝试在 ARM 中创建一个任务队列。基本思路如下。
typedef void (*funcpointer)(void *); // the argument being passed will be a void pointer that I can hopefully typecast
struct sQueue{
funcpointer func_address; // this stores the address of the function to be called
void *func_parameter; // this stores the address of the struct that is passed to the function
uint32_t TimeStamp; // the time at which the function should be called
};
sQueue Func_List[10];
计划是能够将应该调用的函数的地址放在Func_List[x].func_address中。
我希望能够将接受指向不同结构类型的指针的函数的地址放在 func_address 中。 这是一个例子:
void Config_ADC(sADC_Settings *pSettings);
void Enable_RX(sRX_Top_Settings *pSettings);
这两个函数都有效地接受一个指向结构的 32 位指针,但在这些情况下,结构是不同的类型。
当我尝试分配 Func_List[x].func_address = Config_ADC 时,编译器会抱怨:
“void (*)(sADC_Settings *)”类型的值不能分配给“funcpointer”类型的实体
关于如何实现这一目标的任何想法?我当然可以将函数 Config_ADC 更改为接受 void* 指针,然后在函数内部进行类型转换,但我真的不想这样做。
【问题讨论】:
标签: c function-pointers