context-free grammar

Peter Alexander peter.alexander.au at gmail.com
Sat Mar 5 07:44:38 PST 2011


On 5/03/11 1:39 PM, Mafi wrote:
> Am 05.03.2011 13:10, schrieb Peter Alexander:
>> How do you think array assignments in C++ work?
>>
>> a[i] = x;
>>
>> a[i] is just *(a + i), i.e. the evaluation of an expression that yields
>> a temporary, which in this case is an lvalue. Same applies to all other
>> operator[] overloads.
>
> No, the temporary in this case is not an lvalue. It's an adress whose
> value is an lvalue.

(a + i) is an address (type T*)

*(a + i) is a lvalue reference (type T&)

> The results of operator[] is a reference not a normal value. A reference
> is an adress which is always implicitly derefenced when used.
> In D we use opIndexAssign anyways.

A reference is not an address. A reference is a synonym for another 
object. If that other object is an lvalue then the reference is also an 
lvalue.


Sources:

http://www.parashift.com/c++-faq-lite/references.html#faq-8.2
"In compiler writer lingo, a reference is an 'lvalue' (something that 
can appear on the left hand side of an assignment operator)."

http://www.artima.com/cppsource/rvalue.html
"To better distinguish these two types, we refer to a traditional C++ 
reference as an lvalue reference."

http://msdn.microsoft.com/en-us/library/64sa8b1e.aspx
"The operand of the address-of operator can be either a function 
designator or an l-value that designates an object" (I can use the 
address-of operator on *(a+i), and it's not a function designator, 
therefore it is an l-value)


More information about the Digitalmars-d mailing list