This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Suggested warning: "negating an expression of unsigned type does not yield a negative value"


Joe Buck <jbuck@synopsys.com> writes:

> On Mon, Oct 06, 2003 at 06:11:05PM +0200, Falk Hueffner wrote:
> > Joe Buck <jbuck@synopsys.com> writes:
> > > 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 catch.  It seems that the real problem is not negation of
> unsigned values, but negation followed by extension to a potentially
> larger word size.  If you can figure out how to warn specifically
> about that, it might be worth adding.  But it would be tricky.

I'll give it a try, but I'm not sure how to do that right now, warning
about it every time was a lot easier :)

-- 
	Falk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]