在看/usr/include/........中.h头文件对函数接口的定义时,总是能看到在函数结尾加一个_THROW,一时不明白这是什么意思,而且对于有些POSIX和ISO C不承认或未明确的定义的函数不加_THROW,注释中也会特别说明,该函数不会抛THROW,所以查了一下,
这是一个宏定义,是在GNU下的特色。在头文件#include <cdefs.h>中定义:
# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
# define __THROW __attribute__ ((__nothrow__))
# define __NTH(fct) __attribute__ ((__nothrow__)) fct
# else
# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW throw ()
# define __NTH(fct) fct throw ()
# else
# define __THROW
# define __NTH(fct) fct
# endif
# endif
在C语言下为 __attribute__ ((__nothrow__))而__nothrow__表示该函数不会抛出异常,但是在C++中就会定义为throw(),和C++异常有关。