• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: help fixing overflow warning with abs()...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >help fixing overflow warning with abs()... (From: "Sean McBride" <email@hidden>)

  • Prev by Date: help fixing overflow warning with abs()...
  • Next by Date: Re: unions named the same cause compiler error
  • Previous by thread: help fixing overflow warning with abs()...
  • Next by thread: Window Controllers
  • Index(es):
    • Date
    • Thread