R
Robin Haigh
pete said:Robin said:pete said:Robin Haigh wrote:
Trouble is, an enthusiastic reading of 6.5/2 can make all
sorts of things UB, including *p++.
An enthusiastic reading of 6.5/2 should find the footnote:
70)
This paragraph renders undefined statement expressions such as
i = ++i + 1;
a[i++] = i;
while allowing
i = i + 1;
a = i;
Can you see how this footnote helps? I can't
It should clear up that *p++ is defined.
How do you figure that *p++ can be considered to be undefined
according to 6.5/2?
I don't. I've only said that this is the logical conclusion of the claim
made by others in previous threads, namely that the value of p may not be
used for any other purpose than computing its new value.
The footnote doesn't clarify because it doesn't show an allowed example
containing a post-increment. In fact the undefined example a[i++] = i
contains 3 uses of i:
(1) to compute the new value of i
(2) to determine which element of a is modified
(3) to determine the new value of that element
and the contrasted example a = i contains uses 2 and 3, from which one
might paradoxically deduce that use 1 must be the problem. (This is of
course a spot-the-fallacy exercise)
As I said, a line has to be drawn, so that we know what is undefined and
what isn't. The line must be somewhere between the allowed examples and the
undefined examples, but the gap is quite wide and a number of things fall in
the middle. To draw the line, all we can do is try to determine the
intended meaning of the wording. Various readings are possible, but not all
are sustainable.
I suppose it all depends on your tolerance for contradiction. The ability
to believe arguments whose logical consequences are untenable is one of the
peculiarities of the human condition.