Suggested warning: "negating an expression of unsigned type does not yield a negative value"
Jamie Lokier
jamie@shareable.org
Mon Oct 6 17:23:00 GMT 2003
Falk Hueffner wrote:
> > The C and C++ standards require that unsigned values obey modulo 2**N
> > arithmetic, so the value of -x is rigorously defined.
>
> Sure it is. But it is not what is intended. Example: x = 5, then
> -x=4294967291, i.e., p will be advanced by 4294967291 bytes, which is
> way beyond the legal range of p, but happens to work anyway on 32 bit
> architectures (but not on 64 bit architectures).
Good point. That's elusive enough that I saw ptr[-x] and thought it
was was fine; I am now humbly corrected.
-- Jamie
More information about the Gcc
mailing list