Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. lvalue rvalue discussion

lvalue rvalue discussion

Scheduled Pinned Locked Moved C / C++ / MFC
questiondiscussion
21 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Rajkumar R

    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.

    G Offline
    G Offline
    George_George
    wrote on last edited by
    #21

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups