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: | Zalman Stern <zalman@netcom3.netcom.com> |
Newsgroups: | comp.sys.m68k,comp.compilers |
Date: | 1 Oct 1999 10:09:22 -0400 |
Organization: | Netcom |
References: | 99-09-078 99-09-103 99-09-111 |
Keywords: | code, C++ |
In comp.compilers James Jones <jejones@microware.com> wrote:
: cp = &(c = 10);
An example of the above from some real code I had to deal with once upon a
time:
// If key doesn't exist, value is unmodified.
void getkey(const char *key, int &value) {...};
...
{
int value1;
int value2;
getkey("key1", value1 = 42);
getkey("key2", value2 = 17);
// etc...
}
Metrowerks' compiler of the time spit out a warning on this about
passing a temporary into a non-const ref. The programmer (and I use
the term loosely) who wrote the code insisted that doing the
assignment in the function argument was perfectly valid well defined
C++. Metrowerks insisted that their compiler was correct because the
C++ specification does not say the assignment operator returns its
left operand as an lvalue (i.e. a ref to the left operand), but
rather that the assignment must return an lvalue of the type of its
left operand with the value of its left operand.
After asking a number of experts and posting in comp.std.c++, I
decided that Metrowerks interpretation of the standard is correct but
that almost everybody was surprised by this and thought assignment
always returned a ref to the left hand operand. (Of course the above
code is pretty dubious, but it was a major effort convincing its
author to fix it.)
-Z-
Return to the
comp.compilers page.
Search the
comp.compilers archives again.