[PATCH] C undefined behavior fix
Geoff Keating
geoffk@geoffk.org
Sat Jan 5 02:27:00 GMT 2002
Joe Buck <jbuck@synopsys.COM> writes:
> We are defining P2I(p) to preserve bits, and we are defining I2P(i)
> to preserve bits. These two definitions, it seems to me, nail down
> the definition of I2P(P2I(p)+offset). It simply is not
> mathematically consistent to define two functions rigorously (three,
> counting the addition, which does not overflow) and then claim that
> their composition is undefined. ...
I think it would be better if you thought of the third paragraph as an
exception to the second. That is, if 't' is derived from P2I(q), and
I2P(t) does not reference the same object as q, I2P(t) is 'undefined'
rather than the value the previous paragraph would imply.
Or, alternatively, you could think of the third paragraph as an
exception to the first: P2I is 'undefined' when its result would be
used by I2P to violate 6.5.6/8.
However, from the user's point of view, which of these applies makes
no difference, so the paragraph doesn't need to be worded in such a
way as to pick one, and doing so would most likely only confuse
more people.
--
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>
More information about the Gcc
mailing list