lvalue rvalue discussion
-
George_George wrote:
in post #2, what do the following statements mean? Especially the additional [2] after "str" and ["str"] after 1? Any ideas?
George_George wrote:
* ( ( char * ) & var ) = "str"[2]; // * ((char *)&var) too
it is nothing but subscripting an array, here "str" is an constant array of string. it is same as
const char * const szText = "str"; or const char szText[] = {"str"};
* ( ( char * ) & var ) = szText[2];George_George wrote:
varref = 1["str"]; // varref is also an lvalue
"the subscript operator [] is interpreted in such a way that E1[E2] is identical to *((E1)+(E2))" from C++ std. I think 1["str"] is tricking the above expression to *((1) + (pointer to "str")) that is same as "str"[1] which evaluates to *((pointer to "str") + (1)). because adding pointer to index and index to pointer is same.
Great Rajkumar!! Cool reply. For this discussion, http://www.velocityreviews.com/forums/t279868-what-is-lvalue.html[^] It is mentioned,
struct C
{
C& operator=(int);
};C() = 5; // OK to assign to r-value C();
Here is the related description, -------------------- True. But there are compilers (eg VC++) that do allow to bind non-const references to temporary as an extension of the standard. IMO, a conforming compiler should reject the code. -------------------- I can not see in above code there occurs "bind non-const references to temporary". Do you see it occurs? regards, George