什么是围绕一个函数名的括号中是什么意思? [英] What do the parentheses around a function name mean?

查看:177
本文介绍了什么是围绕一个函数名的括号中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目源文件中的一个,我发现这个C函数定义:

In one of my project source files, I found this C function definition:

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

注:没有星号接下来,所以它不是一个函数指针。或者是什么?
什么是用递归调用怎么回事?

Note: there is no asterisk next to foo, so it's not a function pointer. Or is it? What is going on here with the recursive call?

推荐答案

在没有任何preprocessor东西怎么回事,的签名等同于

In the absence of any preprocessor stuff going on, foo's signature is equivalent to

int foo (int *bar)

在我见过人们把看似不必要的括号函数名的时候有两种功能,并具有相同名称的函数宏,以及程序员希望prevent宏扩展唯一的上下文。

The only context in which I've seen people putting seemingly unnecessary parentheses around function names is when there are both a function and a function-like macro with the same name, and the programmer wants to prevent macro expansion.

这种做法一开始会觉得有些奇怪,但C库由<一个设置了precedent href=\"http://programmers.stackexchange.com/questions/159846/why-does-the-c-library-use-macros-and-functions-with-same-name\">providing一些宏和函数具有相同名称的的。

This practice may seem a little odd at first, but the C library sets a precedent by providing some macros and functions with identical names.

一个这样的功能/宏对是 ISDIGIT()。该库可能如下定义它:

One such function/macro pair is isdigit(). The library might define it as follows:

/* 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 */
}

您的功能看起来几乎相同以上,所以我怀疑这是发生了什么事情在你的code了。

Your function looks almost identical to the above, so I suspect this is what's going on in your code too.

这篇关于什么是围绕一个函数名的括号中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆