Core C++ 2019 :: Dan Saks :: Understanding Lvalues and Rvalues

Sdílet
Vložit
  • čas přidán 28. 05. 2024
  • You've probably heard the terms lvalue and rvalue, if only because they occasionally appear in compiler error messages. However, if you have only a vague understanding of what they mean, you're not alone. Lvalues and rvalues aren't actually language features, but rather semantic properties of expressions and sub-expressions. Understanding lvalues and rvalues provides valuable insights into the behavior of built-in operators, the code generated to execute those operators, and the meaning of some otherwise cryptic compiler error messages. Also, understanding lvalues and rvalues is essential background for working effectively with reference types and overloaded operators. This session covers what you need to know about lvalues and rvalues in C++.
    --- --- --- --- ---
    Presented by Dan Saks at Core C++ 2019 conference, the slides can be found at bit.ly/cpp19p5
  • Věda a technologie

Komentáře • 14

  • @agnesakne4409
    @agnesakne4409 Před rokem

    this man is good

  • @JGunlimited
    @JGunlimited Před 4 lety +1

    Perfect! Was stumbling on this topic, great to have an in-depth look.

  • @anthonyrocha8075
    @anthonyrocha8075 Před 2 lety

    This is the best explanation of this topic I've seen so far.

  • @VishalSharma-ys9wt
    @VishalSharma-ys9wt Před 4 lety +2

    Really nice introduction!

  • @0x656e
    @0x656e Před 3 lety

    Such an amazing talk.

  • @tijshoeijmakers3514
    @tijshoeijmakers3514 Před 3 lety +7

    Great talk, but very annoying crowd...

  • @yuwuxiong1165
    @yuwuxiong1165 Před 4 lety

    good intro. i guess one of the other reasons behind the introduction of "reference" is because we want to let compiler to watch out for us not to miss use pointers when it's initialized once and never change.

    • @bonbonpony
      @bonbonpony Před 3 lety

      Nope, the real reason was what he talked about somewhere around 41:21 - operator overloading. Everything else might be considered a bonus. But without introducing references, overloaded operators couldn't work the same way as the built-in operators work. Long story short, if you want operator overloading to work as expected, you gotta introduce references.

  • @JohnDlugosz
    @JohnDlugosz Před 4 lety +7

    I was expecting something for more advanced programmers -- all the newer stuff about prvalue, xvalue, etc. and guaranteed copy elision.
    I think his material predates C++11, and he added some annotations like "now use nullptr" in a _comment_ where the slide has NULL. In (literally, the last 5 minutes (56:40)) he has an appendix to his legacy lesson, saying "C++11 changes things." and speeds through slides on lvalue references and the diagram of all the --value categories, but that appears at 59:23 and he spends a full 90 seconds on it.

    • @jvsnyc
      @jvsnyc Před 3 lety

      I don't know if you worked it all out since then, or just kind of forgot about it for a while. If the latter, I think this talk is fantastic:
      czcams.com/video/km3Urog_wzk/video.html
      It's his only talk that I've seen on CZcams, but is terrific.
      Dan Saks works in the embedded world, and bounces back and forth between C and C++ a lot. There are other tells in the presentation. Who would ever use a non-Class enum in C++ but someone who also uses C almost every day? I think he would have talked some more about the modern twists and turns if his audience didn't keep asking questions, we lost a good five minutes of the end of the talk here. The talk I linked to is great, if you search, there is an alternate version of it with a slightly different scope of coverage.

    • @jvsnyc
      @jvsnyc Před 3 lety

      Also, from the same year, his son (I think) did this lecture, which while not quite the tour-de-force that the other one I linked to was, was also great and went into a few things a little more deeply maybe:
      czcams.com/video/XS2JddPq7GQ/video.html

  • @abdelrhmanahmed1378
    @abdelrhmanahmed1378 Před 3 lety +1

    int x = 6;
    int z = 10;
    int& p =x;
    p = 100;
    cout

    • @bonbonpony
      @bonbonpony Před 3 lety +1

      First tell us why do you expect `z` to contain 200? You never change `z` after you initialized it to 10.
      After you strip all that fuss you put around it, the `z` part of your program boils down to:
      int z = 10;
      cout

    • @ryanpxl
      @ryanpxl Před 3 lety +3

      When you create a reference you bind it at it's initialisation. So from the beginning p is an alias to x. Where ever you see 'p', you can harmlessly replace it with 'x'. So the statement "p=z" is actually "x=z", which is valid. You've changed the value of 'x' not 'z'. If you print out the value of 'x' you should get 10. I think that's how it works.