Related articles |
---|
m68k gcc/egcs question zoltan@bendor.com.au (Zoltan Kocsi) (1999-09-20) |
Re: m68k gcc/egcs question davidwilliams@ozemail.com.au (David Williams) (1999-09-24) |
Re: m68k gcc/egcs question mrs@kithrup.com (1999-09-24) |
Re: m68k gcc/egcs question jejones@microware.com (James Jones) (1999-09-27) |
Re: m68k gcc/egcs question albert@korppi.cs.tut.fi (1999-09-28) |
Re: m68k gcc/egcs question zalman@netcom3.netcom.com (Zalman Stern) (1999-10-01) |
Re: m68k gcc/egcs question zoltan@bendor.com.au (Zoltan Kocsi) (1999-10-01) |
Re: m68k gcc/egcs question zalman@netcom12.netcom.com (Zalman Stern) (1999-10-03) |
Re: m68k gcc/egcs question graham@barnowl.demon.co.uk (Graham Murray) (1999-10-03) |
From: | James Jones <jejones@microware.com> |
Newsgroups: | comp.sys.m68k,comp.compilers |
Date: | 27 Sep 1999 11:33:51 -0400 |
Organization: | Microware Systems Corporation |
References: | 99-09-078 99-09-103 |
Keywords: | C |
Mike Stump wrote:
> a=b=c means fetch c, store into b, fetch b, store into a. It does not
> mean fetch c, and store into both a and b.
>
> Let me quote from ANSI C++:
>
> 5.17 Assignment operators [expr.ass]
>
> 1 There are several assignment operators, all of which group right-to-
> left. All require a modifiable lvalue as their left operand, and the
> type of an assignment expression is that of its left operand. The
> result of the assignment operation is the value stored in the left
> operand after the assignment has taken place; the result is an lvalue.
>
> Do you know of any compilers that don't do it this way? Does the
> wording of the C standard say something else?
Indeed it does:
"3.3.16 [sorry, I don't have the ISO version handy] Assignment Operators
...
Semantics
An assignment operator stores a value in the object designated by the
left operand. An assigment expression has the value of the left operand
after the assignment, but is not an lvalue. The type of an assigment
expression is the type of the left operand unless the left operand has
qualified type, in which case it is the unqualified version of the type
of the left operand....'
So C and C++ differ on this matter; I wouldn't claim to be an authority,
but it's not at all clear to me that the C "abstract machine" requires
in a = b = c that b be both stored to and then loaded from again even if
b has volatile qualified type. (If there really is a difference in this
regard between C and C++, then people moving to C++ stepwise as a
"better C" might receive a surprise.)
Hmmm...if the result of an assignment operator is an lvalue (isn't that
how Algol 68 does it?), then it should be possible to write
(c = 10) += x
...unless the question of updating twice between sequence points renders
the result undefined...OK, we'll sidestep that issue; it should be
possible to write (in C++ but not in C)
cp = &(c = 10);
I'll have to try that out. (We're definitely getting towards comp.std.c
and comp.std.c++ matters here.)
James Jones
[The C9X committee has tried quite diligently to avoid gratuitous
incompatibilities with C++. If I were playing language lawyer, I'd say
that neither spec requires that the intermediate value be refetched, and
if you want to force that, use two statements so there's a sequence point
between them. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.