namespace someNameSpace {
extern "C" void doSomething()
{
someOperations();
}
}
I want to run doSomething()
in both C++ and C environment.
Is someNameSpace
still encapsulating doSomething()
if I expose it to extern "C"
linkage?
Is there a good way to share functions between C++ and C while avoiding polluting global namespace on C++ side?
Edit: Because this code is primarily used in C++ mode, while the C linkage is for test use only, I guess this is a better way to do it.
namespace someNameSpace {
#ifdef COMPILE_FOR_C_LINKAGE
extern "C"
#else
extern "C++"
#endif
{
void doSomething()
{
someOperations();
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…