Declare a C++ function that has C calling convention but internal linkage : <p>I'm trying to interface with a C library, which expects me to provide a pointer to a callback function.</p>

<p>As I understand it, according to the standard the callback must have C <em>language linkage</em>, due to possibly different calling convention. I can accomplish this by declaring my callback function as <code>extern "C"</code>. However this has an undesirable side effect: exposing the function's unqualified and unmangled name to other translation units.</p>

<p>Is it possible to declare a function such that its name has <em>internal linkage</em> (not visible to other translation units), but which can be called from C via a pointer (has appropriate calling convention) using only standard C++?</p>

<p>If it's impossible to make it have <em>internal linkage</em>, is it at least possible to make it keep its C++ name mangling?</p>

<p>I tried:</p>

<ul>
<li>Declaring it as <code>static extern "C" void f();</code> which caused a compilation error to the effect that <code>static</code> and <code>extern "C"</code> cannot be used together.</li>
<li>Declaring it within an anonymous namespace as <code>namespace { extern "C" void f(); }</code> which turned out to have the same effect as regular namespace, exposing the unmangled unqualified name.</li>
</ul>
