Re: sequence points in subexpressions
- From: James Dow Allen <jdallen2000@xxxxxxxxx>
- Date: Sun, 13 Dec 2009 12:58:59 -0800 (PST)
On Dec 14, 2:20 am, Flash Gordon <s...@xxxxxxxxxxxxxxxxx> wrote:
Seebs wrote:
I think it is UB.I think it isn't UB.
I'm not sure. In the simple case:
i = (1, i++, i) + 1;
It may be hard to imagine how the C system
could go wrong, but one might be able to imagine
some cache-speeding trick that assumes it
won't encounter this code (or can do what it wants
with it, if marked UB in The Standard).
For those who think commas are permitted, what about:
*(p += i, ++i, p += i) = j++, ++j, j;
No problem right?
The commas at left separate left-side sequence points,
and commas at right separate (order) a different
set of sequence points. We end up, in effect with
i += 1, *(p += i+i-1) = j += 2;
What do we know about *which* sequence points are
reached first, right-side vs left-side, or can they
be interelaved?
Now what about:
*(p += i, ++i, p += i) = i++, ++i, i;
Definitely UB-lookingish.
In most of the "interesting" edge cases, the right answer is not to go there..
That I definitely agree with. I would reject any code like this I came
across in a code review.
While certainly this code would be rejected,
it *is* good to look at border cases.
On Dec 13, 9:30 pm, Nick <3-nos...@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I often wonder why anyone cares about this sort of statement. It
doesn't look the sort of thing that might be produced by computer
generated code, and it doesn't look the thing you'd actually want to
write into a program. If it's that borderline and you'd never need it,
why does it actually matter, other than as a sort of C language sudoku.
I argued much like this 5 weeks back in a somewhat similar thread and
was rebuked. And the old thread was the same old silly expression
designed
to provoke UB, while OP's query *does* represent a defining corner-
case.
James Dow Allen
.
- Follow-Ups:
- Re: sequence points in subexpressions
- From: Flash Gordon
- Re: sequence points in subexpressions
- References:
- sequence points in subexpressions
- From: amit.codename13@xxxxxxxxx
- Re: sequence points in subexpressions
- From: pete
- Re: sequence points in subexpressions
- From: Richard
- Re: sequence points in subexpressions
- From: mohangupta13
- Re: sequence points in subexpressions
- From: Seebs
- Re: sequence points in subexpressions
- From: Flash Gordon
- sequence points in subexpressions
- Prev by Date: Re: are you sure all you is in the right way?
- Next by Date: Re: What is the gain of "inline"
- Previous by thread: Re: sequence points in subexpressions
- Next by thread: Re: sequence points in subexpressions
- Index(es):
Relevant Pages
|