Does it make sense to use _attribute__ ((nothrow)) inside extern C?

时间:2016-08-31 18:26:53

标签: c++ c gcc attributes extern-c

I have some C code being called from C++.
The header resembles the following:

#ifndef CLibH
#define CLibH

#ifdef __cplusplus
extern "C" {
#endif

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

#ifdef __cplusplus
}
#endif

#endif

Since I'm already using extern C,
is there any benefit to adding the nothrow compiler attribute?

#ifndef CLibH
#define CLibH

#ifdef __cplusplus
extern "C" {
#endif

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

#ifdef __cplusplus
}
#endif

#endif

Does extern C make this redundant?
Are there still advantages to applying it under these circumstances?

1 个答案:

答案 0 :(得分:0)

Yes, it does. From gcc documentation:

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.