From: Ralf Jung Date: Thu, 15 Aug 2024 09:33:47 +0000 (+0200) Subject: reference lvalues/rvalues; fix a typo X-Git-Url: https://git.ralfj.de/web.git/commitdiff_plain/7a9caa32c818812d46c9eb9696a7082cb37c9941?ds=sidebyside reference lvalues/rvalues; fix a typo --- diff --git a/personal/_posts/2024-08-14-places.md b/personal/_posts/2024-08-14-places.md index 107a169..912f7d5 100644 --- a/personal/_posts/2024-08-14-places.md +++ b/personal/_posts/2024-08-14-places.md @@ -35,6 +35,9 @@ That is the topic of this post. +(You might have already encountered the distinction of place expressions and value expressions in C and C++, where they are called lvalue expressions and rvalue expressions, respectively. +While the basic syntactic concept is the same as in Rust, the exact cases that are UB are different, so we will focus entirely on Rust here.) + ### Making the implicit explicit The main reason why this dichotomy of place expressions and value expressions is so elusive is that it is entirely implicit. @@ -68,7 +71,7 @@ However, the expression `my_var` (referencing a local variable), according to th This is because `my_var` actually denotes a place in memory, and there's multiple things one can do with a place: one can load the contents of the place from memory (which produces a value), one can create a pointer to the place (which also produces a value, but does not access memory at all), or one can store a value into this place (which in Rust produces the `()` value, but the side-effect of changing the contents of memory is more relevant). -Besides local variable, the other main example of a place expression is the result of the `*` operator, which takes a *value* (of pointer type) and turns it into a place. +Besides local variables, the other main example of a place expression is the result of the `*` operator, which takes a *value* (of pointer type) and turns it into a place. Furthermore, given a place of struct type, we can use a field projection to obtain a place just for that field. This may sound odd, because it means that `let new_var = my_var;` is not actually a valid statement in our grammar!