[英]noexcept, __declspec(nothrow), throw(), __attribute__(nothrow)
[英]Does it make sense to use _attribute__ ((nothrow)) inside extern C?
我從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
extern C
會使這個多余嗎?
在這種情況下應用它還有優勢嗎?
是的,它確實。 來自gcc文檔:
例如,標准C庫中的大多數函數都可以保證不會拋出帶有函數指針參數的qsort和bsearch的顯着異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.