__THROW是什么东西?

来源:互联网 发布:linux显示环境变量的值 编辑:程序博客网 时间:2024/06/08 07:46

__THROW是什么东西?很多头文件里面对函数的声明后面都跟一个这东西,查了一下,有这么个文章说的清楚,转来看看。

Linux/FreeBSD内核的源文件里常会出现这个东东。其实并不复杂,只是简单的宏定义,可以参考以下代码

<sys/cdefs.h>;:/* GCC can always grok prototypes.  For C++ programs we add throw()   to help it optimize the function calls.  But this works only with   gcc 2.8.x and egcs.  */# if defined __cplusplus && (__GNUC__ >;= 3 || __GNUC_MINOR__ >;= #  define __THROW       throw ()# else#  define __THROW# endif# define __P(args)      args __THROW/* This macro will be used for functions which might take C++ callback   functions.  */# define __PMT(args)    args# define __DOTS     
像这个
static void icmp6_errcount __P((struct icmp6errstat *, int, int)); 
展开后就是
static void icmp6_errcount (struct icmp6errstat *, int, int) throw();
或者
static void icmp6_errcount (struct icmp6errstat *, int, int);
 
__P在c++调用的情况下,会在函数声明后加入 throw()
表明该函数不会扔出异常,这样避免编译器生成对异常的
原创粉丝点击