function pointer does not call a function in CW 5.0

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

function pointer does not call a function in CW 5.0

跳至解决方案
2,370 次查看
FC
Contributor III
Hi,
 
Under CW 5.0, I have declared a simple function pointer:
 
void (*fp) ();
 
the call:
 
fp = &MCU_init;  // just an example
 
In simulation,  fp = the address of MCU_init, but does not execute the function.
I am using the small memory model.  I also used a typedef, but still no luck. 
 
Is it a compiler setting?
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
994 次查看
CrasyCat
Specialist III

Hello

How are you calling the function?

fp = &MCU_init; will only initialize fp with the address of function MCU_init.

To call the function you have to write

fp();

CrasyCat

在原帖中查看解决方案

0 项奖励
回复
2 回复数
995 次查看
CrasyCat
Specialist III

Hello

How are you calling the function?

fp = &MCU_init; will only initialize fp with the address of function MCU_init.

To call the function you have to write

fp();

CrasyCat

0 项奖励
回复
994 次查看
FC
Contributor III
Thanks
Forgot about the call.
 
Besides using function pointers in a table, what other practical uses are there?
0 项奖励
回复