This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Suggested warning: "negating an expression of unsigned type does not yield a negative value"
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