Re: help fixing overflow warning with abs()...
Re: help fixing overflow warning with abs()...
- Subject: Re: help fixing overflow warning with abs()...
- From: Clark Cox <email@hidden>
- Date: Wed, 23 Dec 2009 11:22:33 -0500
On Wed, Dec 23, 2009 at 10:36 AM, Sean McBride <email@hidden> wrote:
> Hi all,
>
> This code:
>
> int foo = ...;
> if (abs(foo) >= 1)
>
> generates this warning:
>
> "warning: assuming signed overflow does not occur when assuming abs (x)
>>= 0 is true [-Wstrict-overflow]"
>
> How would you resolve this? Should abs() simply be avoided because of
> the fact that abs(INT_MIN) returns INT_MIN?
It's not even guaranteed to do that, the result of abs(INT_MIN) is
undefined on any platform where (INT_MIN != -(INT_MAX)). I would avoid
it for just that reason, regardless of the warning, and just use
"if(foo != 0)" or just "if(foo)"
--
Clark S. Cox III
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden