简体   繁体   English

如何在c ++中创建别名(在汇编级别)?

[英]How to make aliases in c++ (on assembly level)?

The question sounds stupid. 这个问题听起来很愚蠢。 Surely, just type: 当然,只需输入:

  int i = 1;
  int &k = i;

But after I compile it with llvm ( optimization flag is -O0 ) I have next intermediate interpretation: 但是在用llvm编译它之后(优化标志是-O0 )我有下一个中间解释:

  %i = alloca i32, align 4                        ; <i32*> [#uses=2]
  %k = alloca i32*, align 8                       ; <i32**> [#uses=2]

It means that i and k are not aliases (as I understand %k contains address of %i). 这意味着ik不是别名(据我所知,%k包含%i的地址)。 How to make an example of aliases? 如何制作别名的例子?

Two pointers are aliased if they point to the same memory location. 如果两个指针指向相同的内存位置,则会将其别名化。 The concept of aliasing is only applicable for pointers - since a non-pointer value cannot point anywhere. 别名的概念仅适用于指针 - 因为非指针值不能指向任何位置。 So in your example i can never alias anything. 所以在你的例子中, i永远不能做任何别名。

If you want an aliasing example, look at this snippet: 如果您需要别名示例,请查看以下代码段:

int i = 1;
int &j = i;
int &k = i;

j and k are aliased. jk是别名。

I'm not exactly sure what you're expecting to see on the LLVM side, especially with -O0 . 我不确定你期望在LLVM端看到什么,尤其是-O0 If you were expecting a global alias , those are unrelated and used to provide a second name to an existing global. 如果您期望全局别名 ,则这些别名不相关并用于为现有全局提供第二个名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM