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?
extern "C"can call straight into C++ code marked asextern "C". So the questions becomes can exceptions propagate out of a C++ function marked asextern "C"?newof course, so it's not redundant at ll. In fact you can externalize any c++ function and use stl, thenewoperator (which does throw exceptions). The only thingextern "C"does is prevent name mangling.