Re: Multiple Assignment Evaluation Debate
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Sat, 11 Mar 2006 18:34:21 GMT
ena8t8si@xxxxxxxxx wrote:
pete wrote:
ena8t8si@xxxxxxxxx wrote:
Richard G. Riley wrote:
"ena8t8si@xxxxxxxxx"posted the following on 2006-03-10:
Richard Heathfield wrote:
berns@xxxxxxxxxxxx said:
Hi All,
A coworker and I have been debating
the 'correct' expectation of
evaluation for the phrase a = b = c.
Two different versions of GCC
ended up compiling this as b = c; a = b
and the other ended up
compiling it as a = c; b = c.
(Both with no optimizations enabled).
How did we notice you may ask?
Well, in our case 'b' was a memory
mapped register that only has a select number
of writable bits. He
claims it has been a 'C Standard'
that it will be evaluted as a = c; b
= c. I personally believe that it
would make more sense for it to be
evaluated as b = c; a = b,
although I would never write code that has a
questionable operation. Can anyone settle this debate?
The point of interest is that
"assignment" is not a sequence point.
If
sorted -> next = *node;
sorted = *node;
is defined, then
sorted = sorted -> next = *node;
is undefined.
Even if that ridiculous claim were true,
The ridiculous claim is true.
The topic comes up on this newsgroup from time to time,
usually in the form of "p = p->next = q"
You can look it up next time you're online.
http://groups.google.com/group/comp.lang.c/search?group=comp.lang.c&q=%22p+%3D+p-%3Enext+%3D+q%22
http://groups.google.com/group/comp.lang.c/msg/1c7e2102fd256d79
"The p = p->next = q problem is also a real problem that came from
a program I was writing when I posted a question about it here
years ago." -- Ben Pfaff
it isn't responsive
to the OP's question. Does the intermediate assignment
influence what value is assigned to a? The answer to that
is YES.
No.
The value of the intermediate assignment
influences what value is assigned to a,
but that value is known prior to the side effect
of the actual assignment taking place.
If you have
unsigned char uc;
unsigned int ui;
ui = uc = -1;
that can be translated as either
uc = UCHAR_MAX;
ui = UCHAR_MAX;
or
ui = UCHAR_MAX;
uc = UCHAR_MAX;
The order in which the side effects take place doesn't matter.
OP's question is entirely an issue of
side effects not being ordered between sequence points.
--
pete
.
- References:
- Multiple Assignment Evaluation Debate
- From: berns
- Re: Multiple Assignment Evaluation Debate
- From: Richard Heathfield
- Re: Multiple Assignment Evaluation Debate
- From: pete
- Multiple Assignment Evaluation Debate
- Prev by Date: Re: representational error in C
- Next by Date: Re: Learning C
- Previous by thread: Re: Multiple Assignment Evaluation Debate
- Next by thread: Re: Multiple Assignment Evaluation Debate
- Index(es):
Relevant Pages
|