gpt4 book ai didi

c - 如何将函数指针映射到其定义?

转载 作者:行者123 更新时间:2023-12-02 21:28:41 29 4
gpt4 key购买 nike

当我查看源代码时,我得到了一个函数指针。所以我使用了ctags -R但我没有得到定义。就像

int (*example)(struct arg1, struct arg2);

如何获得原始函数(定义)?

最佳答案

int (*example)(struct arg1, struct arg2);

上面的行声明了一个名为 example 的变量,其类型为 int (*)(struct arg1, struct arg2)。您可以为其分配一个兼容的函数指针,例如:

int foo(struct arg1 a1, struct arg2 a2) {
// irrelevant
}

int main(void) {
int (*example)(struct arg1, struct arg2); // declare example as a function ptr
struct arg1 a1;
struct arg2 a2;
example = &foo; // assign address of foo to it. BTW, `example = foo;` also works.
example(a1, a2); // call foo
return 0;
}

这就像拥有另一个指针,例如:int *example;,但类型不同。

关于c - 如何将函数指针映射到其定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22828738/

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