__THROW是什么东西?
来源:互联网 发布:淘宝首页推广 编辑:程序博客网 时间:2024/06/08 15:51
__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);
<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()
表明该函数不会扔出异常,这样避免编译器生成对异常的
处理代码,优化生成结果.
//==============================
个人觉得这个解析好点:
首先,__THROW宏是纯粹是linux平台上C库才有的东西,其他平台(如windows)上的C库里是不会有的。在C里面,这个宏完全没有意义。当这个头文件被C++引用时,才有意义,其意义是声明这个函数支持C++里的throw异常功能。看下面一段说明:__THROW is meant to declare the function as capable ofthrowing exceptions (a C++ feature). In C, the macro does nothing.
0 0
- __THROW是什么东西?
- __THROW是什么东西?
- __THROW是什么东西?
- __THROW是什么东西?
- __THROW是什么东西?
- 宏__THROW
- 宏__THROW
- __THROW __nonnull
- ruby语言是什么东西?
- _beginthread是什么东西?
- Ajax是什么东西呢?
- 照片:Majoy是什么东西?
- Thumbs.db是什么东西
- 替代广告是什么东西
- cookie是什么东西?
- 这是什么东西
- ARM是什么东西?
- 市场是什么东西?
- linux进程管理
- Richedit的使用
- 小小人
- <!-- --> 与 <%-- --%>区别!!
- android(3): 有关adb等的操作
- __THROW是什么东西?
- Jquery Table 的基本操作
- java上传文件
- POJ 1595 素数的筛选输出问题
- Python challenge_16
- 想做一个整合开源安全代码扫描工具的代码安全分析平台 - Android方向调研
- block 与 dispatch quene
- 项目经理部的周例会中项目经理要做的事情
- G41 MCH 简介