I'm trying to interface with a C library, which expects me to provide a pointer to a callback function.
As I understand it, according to the standard the callback must have C language linkage, due to possibly different calling convention. I can accomplish this by declaring my callback function as extern "C". However this has an undesirable side effect: exposing the function's unqualified and unmangled name to other translation units.
Is it possible to declare a function such that its name has internal linkage (not visible to other translation units), but which can be called from C via a pointer (has appropriate calling convention) using only standard C++?
If it's impossible to make it have internal linkage, is it at least possible to make it keep its C++ name mangling?
I tried:
- Declaring it as static extern "C" void f();which caused a compilation error to the effect thatstaticandextern "C"cannot be used together.
- Declaring it within an anonymous namespace as namespace { extern "C" void f(); }which turned out to have the same effect as regular namespace, exposing the unmangled unqualified name.
 
    