函数指针声明-__P做什么? [英] Function Pointer Declaration - what does __P do?

查看:133
本文介绍了函数指针声明-__P做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数指针定义的常用形式是:

The usual form of function pointer definitions is:

 int function(int, int);
 int (*ptr)(int, int);

但是我今天看到了一个我不理解的表格.有人可以解释一下吗?

but I saw a form today which I didn't understand. Can anyone explain this please?

int (*close)    __P((struct __db *));

推荐答案

__P()宏通常用于支持从K& RC时代起没有原型(从C89引入C的时代)开始的C实现. ).逻辑基本上是

The __P() macro is usually used to support C implementations from the days of K&R C, when there were no prototypes (which were introduced to C with C89). Basically the logic is

#if SOME_LOGIC_TO_TEST_WHETHER_IMPLEMENTATION_SUPPORTS_PROTOTYPES
#  define __P(argument_list) argument_list
#else
#  define __P(argument_list) () 
#endif

应用于示例时,您能看到它的工作原理吗?请注意,要使此方法起作用并且不会引起语法错误,参数列表必须包含 函数调用 的括号,而不仅仅是 类似函数的宏 .因此,使用宏时会在双括号内.这可能就是它看起来不寻常的原因.

Can you see how this works when applied to your example? Note that for this to work and not cause a syntax error, the argument list must include the parentheses of the function call, not just the parentheses of the function-like macro. Hence the double parentheses when the macro is used. That's probably the reason why it looks unusual.

这篇关于函数指针声明-__P做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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