Why do you need "extern C" for in C++ callbacks to C functions?
- by Artyom
Hello,
I find such examples in Boost code.
namespace boost {
namespace {
extern "C" void *thread_proxy(void *f)
{
....
}
} // anonymous
void thread::thread_start(...)
{
...
pthread_create(something,0,&thread_proxy,something_else);
...
}
} // boost
Why do you actually need this extern "C"?
It is clear that thread_proxy function is private internal and I do not expect that it
would be mangled as "thread_proxy" because I actually do not need it mangled at all.
In fact in all my code that I had written and that runs on may platforms I never used
extern "C" and this had worked as-as with normal functions.
Why extern "C" is added?
My problem is that extern "C" function pollute global name-space and they do not actually
hidden as author expects.
This is not duplicate!
I'm not talking about mangling and external linkage. It is obvious in this code that
external linkage is unwanted!