Does anyone know how to manually mangle names in Visual C++? -
if have function in .c like
void foo(int c, char v);
...in .obj, becomes symbol named
_foo
...as per c name mangling rules. if have similar function in .cpp file, becomes else entirely, per compiler-specific name mangling rules. msvc 12 give this:
?foo@@yaxhd@z
if have function foo in .cpp file , want use c name mangling rules (assuming can without overloading), can declare as
extern "c" void foo(int c, char v);
...in case, we're old
_foo
...in .obj symbol table.
my question is, possible go other way around? if wanted simulate c++ name mangling c function, easy gcc because gcc's name mangling rules make use of identifier-friendly characters, mangled name of foo becomes _zn3fooeic, , write
void zn3fooeic(int c, char v);
back in microsoft-compiler-land, can't create function name invalid identifier called
void ?foo@@yaxhd@z(int c, char v);
...but i'd still function show symbol name in .obj symbol table.
any ideas? i've looked through visual c++'s supported pragmas, , don't see useful.
you can using __identifier
:
#include <stdio.h> #pragma warning(suppress: 4483) extern "c" void __cdecl __identifier("?foo@@yaxhd@z")(int c, char v) { printf("%d %c\n", c, v); } void __cdecl foo(int, char); int main() { foo(10, 'x'); }
Comments
Post a Comment