加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 在extern C中使用_attribute __((nothrow))是否有意义?

发布时间:2020-12-16 06:52:25 所属栏目:百科 来源:网络整理
导读:我从C调用了一些C代码. 标题类似于以下内容: #ifndef CLibH#define CLibH#ifdef __cplusplusextern "C" {#endif//C APIvoid foo(void);// ...#ifdef __cplusplus}#endif#endif 由于我已经在使用extern C, 添加nothrow编译器属性有什么好处? #ifndef CLibH#
我从C调用了一些C代码.
标题类似于以下内容:

#ifndef CLibH
#define CLibH

#ifdef __cplusplus
extern "C" {
#endif

//C API
void foo(void);
// ...

#ifdef __cplusplus
}
#endif

#endif

由于我已经在使用extern C,
添加nothrow编译器属性有什么好处?

#ifndef CLibH
#define CLibH

#ifdef __cplusplus
extern "C" {
#endif

//C API
void foo(void) __attribute__((nothrow));
// ...

#ifdef __cplusplus
}
#endif

#endif

外部C会使这个多余吗?
在这种情况下应用它还有优势吗?

解决方法

是的,它确实.来自gcc文档:

For example,most functions in the standard C library can be guaranteed not to throw an exception with the notable exceptions of qsort and bsearch that take function pointer arguments.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读