Warning flags for unsigned operations (unsafe)

Robert Dewar dewar@gnat.com
Wed Sep 22 16:18:00 GMT 2004


Thomas R. Truscott wrote:
>  > I couldn't find out if gcc had a 
>  > warning flag for unsigned operation. For example, even the linear 
>  > interpolation on [a,b] can be tricky to code:
>  > 
>  >  c = a + t * (b - a);  //unsafe
> 
> Not for this situation.  I think a warning would be appropriate
> when an unsigned quantity involving subtraction
> is widened or converted to double.

Why? The semantics are reasonable, well defined, and expected.
One assumes that in this case either the code expects the wrap
semantics (less likely) or, more likely, knows that the quantity
b-a will be non-negative.

I see nothing special about being widened or converted to double.



More information about the Gcc mailing list