3 ms·
The article starts by explaining lvalues and rvalues more precisely than that, and breaks them up into 3 additional value categories in modern C++ (the ones in
by dbaupp 8y ago
The article starts by explaining lvalues and rvalues more precisely than that, and breaks them up into 3 additional value categories in modern C++ (the ones in the title).
(Also, lvalues aren't tied to the stack: they can be anywhere in memory, like heap or static.)
- leetcrew 8y agohow can you have an lvalue stored in the heap? isn't the lvalue itself a pointer in the stack? obviously I see how it can have static storage.
- dbaupp 8y agoIf foo is an lvalue, then I believe (for example) *(foo[0].bar->baz) is also an lvalue, and those pointer dereferences can go anywhere. Those values occupy a location in memory, as you said, even if it isn't on the stack.
- leetcrew 8y agooh okay, understood. frankly I don't have an airtight understanding of the c++ standards and I would have considered your expression to be a dereference operation on an lvalue, but not an lvalue itself. ty for the explanation!
- simiones 8y agoI'm sure there are some complex exceptions, but as a starter, you can think of lvalues as "anything you can assign to" (the l basically stands for left, as in, "can appear on the left of an assignment"). So, if you have something like `foo(val) = 10`, then `foo(val)` is an lvalue.
- mannykannot 8y agoOne of the complications is that if you take an l-value and const-qualify it, it is still an l-value (but not a modifiable l-value.) https://www.geeksforgeeks.org/lvalue-and-rvalue-in-c-language/ https://www.geeksforgeeks.org/lvalue-and-rvalue-in-c-languag...
- mannykannot 8y agoThey are not mutually exclusive. When a pointer has been set to point to an lvalue, dereferencing it yields that lvalue.
- gumby 8y agoglobal variables are lvalues, for instance.