c++ - Visual C++ 是否提供与 GCC 中的 `__attribute__((alias))` 具有相同功能的语言结构?

标签 c++ c gcc visual-c++

__attribute__((alias)) means:

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/

相关文章:

c - Scanf 跳过 C 中的每个其他 while 循环

c++ - 大数组的C++/CUDA怪异行为

c++ - Oop 中的对象作用域是什么?

c - 是否有可能告诉 gcc 编译器忽略函数属性?或者加快编译时间?

c - 检查多个内含物的最佳方法

c - 为什么 C 是编译器的语言——当 Scheme 子集似乎更合适时?

c++ - 如何以编程方式改进破解替换密码?

c++ - boost asio async_read_some 超时

c++ - 你能在 Arduino (C/C++) 中生成 128 位无符号整数吗?

c - 复合语句的 GCC 评估