gpt4 book ai didi

c++ - 语法 - 可能的函数指针

转载 作者:IT老高 更新时间:2023-10-28 23:11:06 24 4
gpt4 key购买 nike

一行代码让我感到困惑,我无法解决。它可能是函数地址的转换并将其分配给函数指针,但是“地址”不应该在那里。还是我完全断章取义?

int32_t (*const my_func)(uint32_t address) = (int32_t (*)(uint32_t address)) nvm_addr;

最佳答案

int32_t (*const my_func)(uint32_t address)

一个名为 my_func 的变量存储一个指向函数的 const 指针,该函数采用 uint32_t 并返回一个 int32_t。参数名称是可选的,它只是用来说明该参数的语义。

(int32_t (*)(uint32_t address)) nvm_addr

这会将 nvm_addr 转换为指向与 my_func 相同类型的函数的指针。

总的来说,这只是存储指向 nvm_addr 的函数指针的一种相当冗长的方式。

关于c++ - 语法 - 可能的函数指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31477023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com