Article View: comp.std.c
Article #60Re: on "use", and the lvalue-ness of string literals
From: James Kanze
Date: Tue, 03 Nov 1992 20:59
Date: Tue, 03 Nov 1992 20:59
38 lines
1977 bytes
1977 bytes
In article <1992Nov03.074747.16658@x.co.uk> clive@x.co.uk (Clive
Feather) writes:
> > "A string literal is a primary expression.
> > It is an lvalue..."
> >
> > It's an LVALUE. This means that,
> > "foo" = "bar";
> > is legal. Right?
> Wrong. It's not a *modifiable* lvalue.
Many others have pointed out the same thing, but...
Unless I've misunderstood something here, a string literal is an
array. Within an expression, except as the operand of sizeof, an
array decays to a (constant) address of the first element of the
array. I don't believe that this is an lvalue, any more than the
constant 1 is an lvalue.
Even if you replace "foo" by a modifiable array, the given statement
is still illegal.
The fact that a string literal is not *modifiable* refers more to
expressions like:
*"foo" = 'g' ;
This is a syntactically correct statement. I do not think that a
conforming compiler can refuse to compile it. (It may warn about it.)
What actually happens on execution is implementation dependant,
however. This implementation dependancy is what is meant by declaring
a string literal to be non-modifiable.
--
James Kanze GABI Software, Sarl.
email: kanze@us-es.sel.de 8 rue du Faisan
67000 Strasbourg
France
Technical Details
Message-ID:
<KANZE.92Nov3205941@slsvdnt.us-es.sel.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!taco!gatech!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!wupost!gumby!yale!yale.edu!ira.uka.de!slsvaat!josef!kanzeReferences:
<1992Nov2.162310.10094@ichips.intel.com> <1992Nov03.074747.16658@x.co.uk>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!taco!gatech!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!wupost!gumby!yale!yale.edu!ira.uka.de!slsvaat!josef!kanze From: kanze@us-es.sel.de (James Kanze) Subject: Re: on "use", and the lvalue-ness of string literals In-Reply-To: clive@x.co.uk's message of 3 Nov 92 07:47:47 GMT Message-ID: <KANZE.92Nov3205941@slsvdnt.us-es.sel.de> Sender: news@us-es.sel.de Organization: SEL References: <1992Nov2.162310.10094@ichips.intel.com> <1992Nov03.074747.16658@x.co.uk> Date: 3 Nov 92 20:59:40 Lines: 39