Is primitive assigned a memory address?

后端 未结 4 2087

I am trying to understand the process of declaration and assignment of a primitive type at the back stage.

  1. int i;
  2. i = 3;
4条回答
  •  时光取名叫无心
    2021-01-12 17:12

    There are not always addresses involved. The compiler can put variables into registers if it finds that their address is never taken by the programmer. So you wouldn't need any access to the main memory. For example in your code above, what the compiler could generate could be as simple as

    add $2, $0, 3
    

    to put value 3 into register 2. As soon as you create a pointer and make it point to that variable, then you have an address, actually. And then the variable cannot be in a register only anymore.

提交回复
热议问题