Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #169226

Re: lvalue assignment difference between C and C++

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: lvalue assignment difference between C and C++
Date 2023-02-08 23:46 +0000
Organization A noiseless patient Spider
Message-ID <87wn4rk9ff.fsf@bsb.me.uk> (permalink)
References (2 earlier) <20230206141733.165@kylheku.com> <87mt5qe7pc.fsf@nosuchdomain.example.com> <0f9840b3-7421-47ae-a507-0069cbfed700n@googlegroups.com> <871qn1mohw.fsf@bsb.me.uk> <9f807ac3-fe63-4caa-ac7d-a8d1c849620an@googlegroups.com>

Show all headers | View raw


Paul N <gw7rib@aol.com> writes:

> On Tuesday, February 7, 2023 at 4:25:44 PM UTC, Ben Bacarisse wrote:
>> Paul N <gw7...@aol.com> writes: 
>> 
>> > On Monday, February 6, 2023 at 10:43:27 PM UTC, Keith Thompson wrote: 
>> >> Right, and the way C (non-normatively) defines "rvalue" is a bit odd. 
>> >> An lvalue is a kind of expression, but an rvalue is the result of 
>> >> evaluating an expression. 
>> >> 
>> >> Historically, lvalues and rvalues were kinds of values. An expression 
>> >> could be "evaluated for its lvalue" or "evaluated for its rvalue", 
>> >> depending on the context in which it appears. In particular, the left 
>> >> hand side of an assignment is evaluated for its lvalue (the identify of 
>> >> the object it designates), and the right hand side of an assignment is 
>> >> evaluated for its rvalue. Some expressions, such as 42, have rvalues 
>> >> but not lvalues; thus 42 cannot appear on the LHS of an assignment. 
>> >> This probably goes back to BCPL, or perhaps even CPL. 
>> > 
>> > Yes, that is how it worked in BCPL. In fact, BCPL has keywords LV and 
>> > RV which can be used to evaluate an expression in its other context,
>> That was very early BCPL. By the time the book was published (and when 
>> I first used it) all references to rvalues and lvalues had gone! I 
>> think the very detailed distinction made early on was probably a 
>> hangover from CPL and was subsequently found to be unnecessarily fussy.
>
> I got my information from two books. One, entitled "Programming
> electronic switching systems" and dated 1976, briefly discusses
> various programming languages and mentions the two types of evaluation
> as a key feature of the language, together with keywords RV and LV. It
> describes an array access as either RV (E1 + E2) or as E1 ↓ E2 (a
> downward arrow). It's possible the authors had not kept up with recent
> developments in the language, which is but one of over a dozen
> described.
>
> The other book is "BCPL: The language and its compiler", dated 1980,
> printed 1986. As you say, there appears to be no mention of lvalues or
> rvalues, and no discussion of LV and RV, but the latter are shown in
> the sample code for the language's syntax analyser. LV seems identical
> to @ but RV and ! are different as the latter can also be used for
> arrays, which are now E1 ! E2 as you say below.

I've got that one (well, had that one would be more accurate) and it
describes what I would call "modern BCPL", if anything from last century
can be modern!

Binary ! is a separate thing.  I was wondering if rv and lv are exactly
unary ! and @ in modern BCPL.  I need to find more examples of rv and lv
being used in code to be sure.

>> > but the symbols @ and ! can also do this - I guess the symbols were 
>> > added later and people used them instead,
>>
>> The early manual (with _lv_ and _rv_ operators) is of the old-school 
>> type where the syntax is given using presentation symbols (often 
>> underlined) that will map to some concrete representation in a 
>> particular implementation. I never used BCPL that old, so I don't know 
>> what was used for _rv_ and _lv_ in practice. Other underlined symbols 
>> were usually written in upper case so I'd guess RV and LV. Did you use 
>> (or even see) BCPL of the era? Though off-topic, I'd love to see some! 
>
> I don't think there are any underlines of any sort in the book.

I used Usenet _underline_ notation for putting an line under a word.
Some clients will _underline_ and make *bold* and /italic/ text using _,
* and / characters.  I think that ended up confusing the matter.

And I was referring only the very old reference manuals.  They were
typically typed with a mechanical typewriter and used underlining to
denote abstract symbols like rv, if, let etc..  In such a notation, a
keyword like let would be underlined and the reader would not
automatically assume that a variable could not be named let.  An
implementation would specify how these symbols should really be written
in actual program texts.  In the BCPL I used, keywords were written in
UPPER CASE, so you could have

  LET let = 42; // not a good idea

Algol 68 used a similar system with bold keywords that could be
represented in several ways.  Upper case was one, but sometimes you
could use quotes or single dots: WHILE, 'while', .while were all seen
where the report used bold while.  (This was called stropping, but I
don't know why.  A metaphorical 'sharpening'?)

I think this convention had died out by the 1980s.

> Full stops seem to be the preferred character for concatenating words
> into a single identifier.

Yes, I think that's always been the case.  I was not talking about
that.  My post was confusing.

>> I'm not 100% sure that the later @ (essentially "address-of") and unary 
>> ! (essentially "dereference") are exactly what the 1967 manual writes as 
>> _rv_ and _lv_. There are enough other differences in that early version 
>> (and the example code at the end is sadly missing) for it to be unclear, 
>> at least to me. Do you know if they were, in fact, just concrete 
>> representations of those keywords?
>
> As I said, the older book certainly seems to say that the keywords
> were simply RV and LV, in capitals.
>
>> > leading to C's @ and *.
>> You mean C's & and *.
>
> Mea culpa!
>
>> In the later BCPL, ! was also binary with a!b 
>> being, essentially, C's a[b]. Early BCPL (which is the form that 
>> influenced B and C) used the very clumsy a*[b] form because []s were 
>> also used for function calls. That syntax, sin[pi], definitely comes 
>> from CPL. 
>
> Yes, both round and square brackets are function calls.
>
> Glad to find someone who is interested!

Thanks for posting.  I'd forgotten all about the original RV and LV
symbols.

I was very fond of programming in BCPL and I think a fast, clean
typeless language would still find place these days.  It's and odd
fondness since I also like very strict typing as in, say, Haskell.  Have
you had a look at Richard's MCPL?  Very interesting...

And, as an aside, somewhere along the line BCPL acquired a%b the byte
offset version of a!b.  You might remember that string operations were
rather painful without it.

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-04 15:30 +0000
  Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-04 11:04 -0500
    Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-04 16:59 +0000
      Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-04 13:02 -0500
      Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-04 12:45 -0800
      Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-05 11:42 +0100
        Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-06 09:26 +0000
          Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-06 14:13 +0100
            Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-06 15:50 +0000
              Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-06 20:08 +0100
              Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 12:47 -0800
          Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 13:03 -0800
            Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-07 09:24 +0000
              Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-07 11:08 -0800
                Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-08 09:23 +0000
                Re: lvalue assignment difference between C and C++ Blue-Maned_Hawk <bluemanedhawk@gmail.com> - 2023-02-08 22:13 -0500
                Re: lvalue assignment difference between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-02-08 22:53 -0500
                Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-08 22:12 -0800
              Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 02:52 +0000
      Re: lvalue assignment difference between C and C++ Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-06 09:11 +0200
        Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 01:01 -0800
          Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-06 07:42 -0500
            Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 12:59 -0800
        Re: lvalue assignment difference between C and C++ bart c <bart4858@gmail.com> - 2023-02-06 08:11 -0800
          Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-06 21:19 +0000
        Re: lvalue assignment difference between C and C++ Bonita Montero <Bonita.Montero@gmail.com> - 2023-02-07 07:44 +0100
          Re: lvalue assignment difference between C and C++ Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 09:18 +0200
    Re: lvalue assignment difference between C and C++ Kaz Kylheku <864-117-4973@kylheku.com> - 2023-02-06 22:21 +0000
      Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 14:43 -0800
        Re: lvalue assignment difference between C and C++ Paul N <gw7rib@aol.com> - 2023-02-07 03:17 -0800
          Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-07 16:25 +0000
            Re: lvalue assignment difference between C and C++ Paul N <gw7rib@aol.com> - 2023-02-08 13:19 -0800
              Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 23:46 +0000
  Re: lvalue assignment difference between C and C++ Bonita Montero <Bonita.Montero@gmail.com> - 2023-02-04 19:41 +0100
  Re: lvalue assignment difference between C and C++ Andrey Tarasevich <andreytarasevich@hotmail.com> - 2023-02-10 16:19 -0800

csiph-web