• 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: 0 < -1 !!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 0 < -1 !!


  • Subject: Re: 0 < -1 !!
  • From: John <email@hidden>
  • Date: Thu, 22 Jul 2004 22:23:09 -0500

On Jul 22, 2004, at 9:48 PM, Jerry LeVan wrote:

[snip]

When currentIndex was zero and [excutedStatements count] was zero
the method was returning YES ie 0 < -1 is true !

[snip]

After squandering several hours ( it took a while to see what the problem was).
I Read The Fine Manual and it told me that the count method returns an "unsigned"


The signed integer -1 is stored in hexadecimal as 0xFFFFFFFF. This number, when evaluated as an unsigned int, is the decimal number 4294967295. When 0 is compared to 0xFFFFFFFF, and the latter is interpreted as unsigned, you're evaluating 0 < 4294967295, not 0 < -1.

I guess I have to go back and review how expressions are evaluated.

The fix was....

currentIndex < (int)[executedStatements count] - 1


The cast forces 0xFFFFFFFF be evaluated as signed, which means -1 when count == 0.

Hope this helps.

John
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >0 < -1 !! (From: Jerry LeVan <email@hidden>)

  • Prev by Date: Re: Adding Bindings to NSOutlineView versus a horrible hack
  • Next by Date: Conf files?
  • Previous by thread: 0 < -1 !!
  • Next by thread: Re: 0 < -1 !!
  • Index(es):
    • Date
    • Thread