alias ("target")
The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified. For instance,
void __f () { /* Do something. */; } void f () __attribute__ ((weak, alias ("__f")));
defines
f
to be a weak alias for__f
. In C++, the mangled name for the target must be used. It is an error if__f
is not defined in the same translation unit.Not all target machines support this attribute.
最佳答案
您可以为 C 执行类似的操作。对于 msvc v19.15,x86 和 x64 支持此操作。
#include <stdio.h>
void __f() { puts("This function is aliased"); }
void f();
#pragma comment(linker, "/alternatename:f=__f")
int main()
{
f();
}
查看编译演示 here .
我已经在 Visual Studio 2017 中使用 /TC
选项对此进行了测试。
关于c++ - Visual C++ 是否提供与 GCC 中的 `__attribute__((alias))` 具有相同功能的语言结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53381461/