gpt4 book ai didi

c - 函数名称周围的括号是什么意思?

转载 作者:太空狗 更新时间:2023-10-29 16:13:48 24 4
gpt4 key购买 nike

在我的一个项目源文件中,我找到了这个 C 函数定义:

int (foo) (int *bar)
{
return foo (bar);
}

注意:foo 旁边没有星号,所以它不是函数指针。或者是吗?递归调用是怎么回事?

最佳答案

在没有任何预处理器的情况下,foo 的签名等同于

int foo (int *bar)

我见过人们在函数名称周围放置看似不必要的括号的唯一情况是,同时存在同名的函数和类似函数的宏,而程序员想要防止宏扩展。

这种做法乍一看可能有点奇怪,但 C 库开创了先例 providing some macros and functions with identical names .

一个这样的函数/宏对是isdigit()。图书馆可能将其定义如下:

/* the macro */
#define isdigit(c) ...

/* the function */
int (isdigit)(int c) /* avoid the macro through the use of parentheses */
{
return isdigit(c); /* use the macro */
}

您的函数看起来与上面几乎相同,所以我怀疑这也是您的代码中发生的事情。

关于c - 函数名称周围的括号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13600790/

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