c++ - g++ 模板名称修改

标签 c++ templates g++ inline-assembly name-mangling

我需要在 g++ 内联汇编中使用模板类成员的地址(作为编译时常量值)。可以这样表达吗? (我认为我需要 T<U>::x 的损坏名称)。

template < typename U >
struct T {
  static int x;
};

template < typename U >
void f () {
  asm ("somecommand T<U>::x");
}

最佳答案

假设您使用的是 linux,则可以使用 nm。

nm --demangle foo.o 为您提供符号的 demangled 名称 nm --no-demangle foo.o 为您提供符号的错位名称。

然后您可以比较这 2 个文件的输出,以将经过修饰的名称与经过修饰的名称进行匹配。

关于c++ - g++ 模板名称修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4085591/

相关文章:

c++ - 模板化 << friend 在与其他模板化 union 类型相互关联时不工作

rest - 使用 DocuSign REST API 获取/设置模板字段

c++ - 无法理解这是循环依赖还是 Clang

c++ - 如何防止从 `0` 构造 std::string 引起的麻烦?

c++ - 从 GCC 获取优化的源代码

c++ - 使用 nvcc 的可执行文件比使用 gcc/g++ 和 OpenCL 的要大

c++ - 代码中 strncpy 到 strcpy 的等效性

c++ - 如何从 QGLWidget 录制视频?

c++ - Visual Studio 2015 缩进多行 for 语句

c++ - 在 omp parallel for 循环中使用 unique_ptr<CCfits::FITS> 导致 SEG.FAULT