How are rvalues in c++ stored in memory?

后端 未结 2 1076
感动是毒
感动是毒 2021-02-08 15:05

Trying to learn lvalues, rvalues and memory allocation for them. So with a lot of learning materials there is a bit of chaos.

An rvalue

2条回答
  •  隐瞒了意图╮
    2021-02-08 15:11

    Short answer: it's implementation dependent.

    The main reasoning behind this is as always freedom for the compiler to improve performances of your code. A more concrete way to understand this is to remember that a value can be stored in a register of your CPU and never actually be in your memory which more or less means that the value has no address. I won't bet everything i have on it but this is probably one of the main reasons why "we cannot get an address of an rvalue".

    In a more general way since an rvalue is semantically temporary it is more likely to be put in temporary places or optimised in a way where it cannot easily be mapped to an address and even if it can that would be counter productive in terms of performance.

提交回复
热议问题