嵌入式C函数宏问题
我在使用 C 的嵌入式硬件中遇到了这个。
#define EnterPWDN(clkcon) ( (void (*)(int))0xc0080e0 ) (clkcon)
我不知道这个函数宏是如何工作的。我知道 clkcon 是 EnterPWDN 的函数参数,但是之后发生了什么?
I came across this in embedded hardware using C.
#define EnterPWDN(clkcon) ( (void (*)(int))0xc0080e0 ) (clkcon)
I have no idea how is this function macro working. I understand clkcon
is the function parameter to EnterPWDN, but what is happening after that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它将地址
0xc0080e0
转换为指向函数的指针,该函数采用int
并返回void
,并调用该函数,传递clkcon
code> 作为参数。详细说明:(
如果您还没有遇到过函数指针,您可能需要 获取一份很好的 C 简介并阅读该主题。)
It casts the address
0xc0080e0
to a pointer to function taking anint
and returningvoid
, and calls that function, passingclkcon
as the parameter.Spelled out:
(If you haven't come across function pointers, you might want to grab a good C introduction and read up on the subject.)
它是一个 void 函数指针,以 int 作为参数。该函数保存在特定的内存地址0xc0080e0。
上面是一个函数指针声明。首先是 void 返回类型。接下来的事实是它是一个指针,最后 int 告诉您函数的参数是什么。内存地址是函数存储的位置,整个过程就是将该内存地址转换为正确的函数指针类型,然后调用该函数并将“clkcon”传递给它。
Its a void function pointer that takes an int as a parameter. The function is held at the specific memory address 0xc0080e0.
The above is a function pointer declaration. First comes the void return type. Next comes the fact that its a pointer and finally the int tells you what the parameter to the function is. The memory address is the location the function is stored at and the whole thing is casting that memory address into the correct function pointer type and then calling the function and passing "clkcon" to it.
优秀的答案 Goz 和 sbi< /a>,但换句话说:
在内存中(可能在 ROM 中)的特定地址 (
0xc0080e0
) 处,有一个函数。您可以使用 int clkcon 参数调用此函数。Excellent answers Goz and sbi, but to put it another way:
At a specific address (
0xc0080e0
) in memory, possibly in a ROM, there is a function. You call this function with theint clkcon
argument.