ROM中的功能指针 [英] Pointer to function in ROM
问题描述
我有正在使用的微控制器。调试时,必须从ROM中硬编码的函数中调用。技术参考显示了如何执行此操作:
I have microcontroler that I am working with. When debugging it is necessary to call a function from that is hard coded in ROM. Technical Reference shows how to do this:
# define Device_cal (void(*)(void))0x3D7C80
,调用过程如下:
(*Device_cal)()
我不明白这里实际上发生了什么,所以我的问题是:
它是如何工作的?
I can't understand what actually happens here, so my question is: How does it work?
推荐答案
#define
会导致(* Device_cal)()
在编译之前立即扩展为:
The #define
causes (*Device_cal)()
to be expanded into this immediately before compiling:
(*(void(*)(void))0x3D7C80)()
void(*)(void)
是函数指针的声明,该函数指针使用 void
并返回 void
类型。 (*())
表示表达式中下一个令牌的转换( 0x3D7C80
)。因此,这要求将位置 0x3D7C80
处的数据视为函数。最后的()
调用不带参数的函数。
The void(*)(void)
is a declaration for a function pointer that takes void
and returns void
types. The (*())
represents a cast for the next token in the expression (0x3D7C80
). Thus this asks to treat the data at location 0x3D7C80
as a function. The final ()
calls the function with no arguments.
这篇关于ROM中的功能指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!