On Clang and GCC (and GCC-like compilers), you can use "asm labels" on functions and variables to set their mangled symbol name, like this:
int f() asm("g");
int f() { return 42; }
int x asm("y") = 42;
This syntax doesn't work on MSVC (Visual Studio). Does Microsoft support any C or C++ source-level syntax for this kind of thing? Note that in this simple case it's possible to just write the name g
in the source code anyway, like this:
extern "C" int g();
int g() { return 42; }
but I'm looking for a way that mimics GCC/Clang's approach — specifically to decouple the C++-source-code name f
from the object-file mangling g
.