c++ - MSVC equivalent of GCCClang `int f() asm("g")`? - Stack Overflow

admin2025-04-16  2

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.

转载请注明原文地址:http://anycun.com/QandA/1744787462a87621.html