🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #64

Re: on "use", and the lvalue-ness of string literals

#64
From: Larry Jones
Date: Tue, 03 Nov 1992 22:08
60 lines
3346 bytes
In article <FRANL.92Nov3115154@draco.centerline.com>, franl@centerline.com (Fran Litterio) writes:
> Was the term "non-modifiable l-value" invented by ANSI, or was it
> "prior art"?  I was always taught that the 'l' in "l-value" comes from
> the idea that an l-value is what can appear on the left-hand-side of
> an assigment expression.
> 
> A non-modifiable l-value sounds a lot like an r-value to me.

It's sort-of an ANSI invention.  K&R defines lvalue in A.5 as:

	An object is a manipulatable region of storage; an lvalue is an
	expression referring to an object.

and gave the etymology:

	The name "lvalue" comes from the assignment expression E1 = E2
	in which the left operand E1 must be an lvalue expression.

However, consider an array: it is certainly a "manipulatable region of
storage" and thus the name of an array should be an lvalue.  However, in
A.14.3 K&R says:

	Every time an identifier of array type appears in an expression,
	it is converted into a pointer to the first member of the array.
	Because of this conversion, arrays are not lvalues.

But this is faulty because the description of sizeof in A.7.2 says:

	When applied to an array, the result is the total number of
	bytes in the array.

The argument to sizeof (in this case) is an expression, so the array
name should have been converted to a pointer, in which case the size
information is no longer available.  Although this is contradictory,
it's not too dificult to figure out what is intended.  K&R also allowed
structures and unions, which should be lvalues according to the
definition, but disallowed structure and union assignment by caveat
without actually declaring that they are not lvalues as it did for
arrays.

The fundamental problem is that there are actually *three* types of
expressions: an expression that designates an object that can be
assigned to (the traditional lvalue), an expression that designates an
object that can't be assigned to (arrays, structs and unions in K&R C,
const expressions in ANSI C), and an expression that does not designate
any object but just a value (the traditional rvalue).  In order to be
rigorous, X3J11 felt it had to have three separate terms for the three
types of expressions.  The final choice came down to using lvalue and
rvalue in their historical sense and making up a new term for "things
that are like lvalues but can't actually appear on the left of an
assignment" (which no one had a good term for), or using lvalue in the
sense of its definition as an expression that designates an object and
then using the adjectives "modifiable" and "non-modifiable" to
differentiate between those expressions that can actually occur on the
left of an assignment and those that can't.  You know what the decision
was.
----
Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
larry.jones@sdrc.com  or  ...uunet!sdrc!larry.jones
That gives me a FABULOUS idea. -- Calvin
Technical Details
Message-ID: <2210@sdrc.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!sdrc!thor!scjones
References: <1992Nov2.162310.10094@ichips.intel.com> <FRANL.92Nov3115154@draco.centerline.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sdrc!thor!scjones
From: scjones@thor.sdrc.com (Larry Jones)
Newsgroups: comp.std.c
Subject: Re: on "use", and the lvalue-ness of string literals
Message-ID: <2210@sdrc.COM>
Date: 3 Nov 92 22:08:43 GMT
References: <1992Nov2.162310.10094@ichips.intel.com> <FRANL.92Nov3115154@draco.centerline.com>
Sender: news@sdrc.COM
Lines: 60