Why is it illegal to take the address of an rvalue temporary?

前端 未结 6 1868
甜味超标
甜味超标 2020-11-27 05:34

According to \" How to get around the warning "rvalue used as lvalue"? \", Visual Studio will merely warn on code such as this:

int bar() {
   retu         


        
6条回答
  •  爱一瞬间的悲伤
    2020-11-27 05:45

    You're right in saying that "temporaries are not guaranteed to even have storage", in the sense that the temporary may not be stored in addressable memory. In fact, very often functions compiled for RISC architectures (e.g. ARM) will return values in general use registers and would expect inputs in those registers as well.

    MSVS, producing code for x86 architectures, may always produce functions that return their values on the stack. Therefore they're stored in addressable memory and have a valid address.

提交回复
热议问题