Ambiguity in semantics of assignments?

D

Dave Vandervies

Thomas Stegen said:
There is really nothing to discuss.

int i = 3;
i = i + 1;

is valid. There is no real difference between the above
and code posted by the OP.

Chapter and verse?

(You could cheat and just point to my post replying to Arthur's request
for chapter and verse. But, based on the discussion we've seen, it's
obviously not immediately and universally clear that this is the case.)


dave
 
C

Chris Torek

What I am unsure about is what the following means:

"The order of evaluation of the operands is unspecified.
If an attempt is made to modify the result of an assignment
operator or to access it after the next sequence point,
the behavior is undefined."

Which is 6.5.16#4

How can you modify the result of an assignment operator?

I believe this refers to tricks like this:

struct S { int a[10]; };

struct S s1, s2;
int *p;

p = (s1 = s2).a;
p[2] = 42; /* presumably, this violates 6.5.16#4 */

This "accesses it after a sequence point" *and* modifies it; to
just modify it, all in one swell foop as it were, we might write:

(s1 = s2).a[2] = 42;

eliminating the variable "p" entirely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,378
Latest member
BlakeLig

Latest Threads

Top