Re: Why does NSArray count return NSUInteger?

2011-05-31 Thread Graham Cox
On 31/05/2011, at 7:36 PM, julius wrote: > > On 31 May 2011, at 10:00, Alejandro Rodríguez wrote: > >> It's more than likely that it has to do with the underlying implementation >> of NSArray which is surely based on C arrays. >> >> NSArray is toll-free bridged with CFArray which being par

Re: Why does NSArray count return NSUInteger?

2011-05-31 Thread julius
On 31 May 2011, at 10:00, Alejandro Rodríguez wrote: > Hey Julius, > > The reason for using NSUInteger on such a high level framework as Cocoa may > not seem relevant but for the sake of completeness let me go down a road less > explored by many of the other answers. I think using NSUInteger v

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Andy Lee
On May 30, 2011, at 6:57 PM, Greg Guerin wrote: > julius wrote: > >> My question is >> Why did Cocoa developers make NSArray count return NSUInteger? > > > It's impossible to answer with certainty. The person or persons who made > that decision are not on this list (AFAIK). Nor have they docu

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Ross Carter
On May 30, 2011, at 9:38 PM, Graham Cox wrote: > On 31/05/2011, at 11:06 AM, koko wrote: > >> Nothing but mental masturbation ... give it a rest ... moderator, do your >> job, please. > > > Get out of bed the wrong side today? > > Quincey is one of the most helpful contributors on the list; y

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Graham Cox
On 31/05/2011, at 11:06 AM, koko wrote: > Nothing but mental masturbation ... give it a rest ... moderator, do your > job, please. Get out of bed the wrong side today? Quincey is one of the most helpful contributors on the list; you might remember that next time you want help. There's always

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Lee Ann Rucker
>Unfortunately, somebody decided a long time ago, the same can't be done for >integers, because there's no infinite-range numerical space available to >machine computation (in any way that mainstream hardware supports directly), >and no single finite-range space that (as in the floating point ca

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread koko
Nothing but mental masturbation ... give it a rest ... moderator, do your job, please. -koko On May 30, 2011, at 4:43 PM, Quincey Morris wrote: > On May 30, 2011, at 15:14, julius wrote: > >> I'm definitely off to the north coast. > > I *wish* people would stop using that old "saving the dis

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Graham Cox
On 31/05/2011, at 8:57 AM, Greg Guerin wrote: > julius wrote: > >> My question is >> Why did Cocoa developers make NSArray count return NSUInteger? > > In a practical sense, none of this matters. The decision was made long, long > ago. It is what it is. You're too late to save that sheep fr

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Greg Guerin
julius wrote: My question is Why did Cocoa developers make NSArray count return NSUInteger? It's impossible to answer with certainty. The person or persons who made that decision are not on this list (AFAIK). Nor have they documented the rationale behind their design decisions for poste

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Quincey Morris
On May 30, 2011, at 15:14, julius wrote: > I'm definitely off to the north coast. I *wish* people would stop using that old "saving the distressed sheep" line to put an end to a thread. It's happening far too often these days. ___ Cocoa-dev mailing

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread julius
On 30 May 2011, at 22:34, Quincey Morris wrote: > On May 30, 2011, at 13:45, julius wrote: > >> Hilarity and riot. > > Glad to have been of service. > >> Here is a nice instance that I think quite germane. >> >> The input parameter to NSArray's objectAtIndex: is an NSUInteger. >> Both these c

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread mlist0...@gmail.com
Maybe this will assuage your outrage (excuse the lame programmer poetry): If you were to look at the apis for NSArray and see that indices are signed integers, you could reasonably conclude that storing/retrieving an object from a negative index is a legitimate thing to do. That would maybe be

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Quincey Morris
On May 30, 2011, at 13:45, julius wrote: > Hilarity and riot. Glad to have been of service. > Here is a nice instance that I think quite germane. > > The input parameter to NSArray's objectAtIndex: is an NSUInteger. > Both these code snippets work perfectly (they retrieve element 3). > zS

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread julius
On 30 May 2011, at 21:56, Dave Zarzycki wrote: > On May 30, 2011, at 1:45 PM, julius wrote: > >> >> On 30 May 2011, at 20:03,Quincey Morris wrote >>> >>> On May 30, 2011, at 08:27, julius wrote: >>> All I had hoped was that someone on this list might illuminate the issue more than

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Sean McBride
On Mon, 30 May 2011 13:56:38 -0700, Dave Zarzycki said: >As others have pointed out, this has nothing to do with Objective-C or >Cocoa. This behavior is true of any C derived language or library. If >this aspect of C bothers you, then please consider adding -Wconversion >to your project's build se

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Dave Zarzycki
On May 30, 2011, at 1:45 PM, julius wrote: > > On 30 May 2011, at 20:03,Quincey Morris wrote >> >> On May 30, 2011, at 08:27, julius wrote: >> >>> All I had hoped was that someone on this list might illuminate the issue >>> more than has happened so far. >> >> The problem isn't really lack of

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread julius
On 30 May 2011, at 20:03,Quincey Morris wrote > > On May 30, 2011, at 08:27, julius wrote: > >> All I had hoped was that someone on this list might illuminate the issue >> more than has happened so far. > > The problem isn't really lack of illumination, but that you're not prepared > to accep

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread julius
On 30 May 2011, at 16:40, Roland King wrote: > > On 30-May-2011, at 11:05 PM, julius wrote: > >> >> On 30 May 2011, at 15:52, Roland King wrote >>> >>> On 30-May-2011, at 9:18 PM, julius wrote: >>> > They used the datatype which maps onto the thing they are describing, > arr

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Gary L. Wade
On 31/05/2011, at 12:03 AM, julius wrote: > has the potential to create problems if it skips one's mind On 05/30/2011 8:40 AM, "Roland King" wrote: > Whist seeing your side... You know, we could really take this to the extreme and I could get upset that Roland started talking about a card gam

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Bruce Turner
A couple of other issues about the use of NSUInteger throughout the Foundation Framework. Core Foundation functions tend to use CFIndex and CFRange, both signed. This is true for CFArray and other collections. If you mix Foundation and Core Foundation you have to deal with this. Many C fu

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Quincey Morris
On May 30, 2011, at 08:27, julius wrote: > All I had hoped was that someone on this list might illuminate the issue more > than has happened so far. The problem isn't really lack of illumination, but that you're not prepared to accept the consequences of the explanation. Here's my version of t

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Roland King
On 30-May-2011, at 11:05 PM, julius wrote: > > On 30 May 2011, at 15:52, Roland King wrote >> >> On 30-May-2011, at 9:18 PM, julius wrote: >> >>> They used the datatype which maps onto the thing they are describing, array elements are non-negative integers, so they used NSUIntege

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread julius
On 30 May 2011, at 16:02, Graham Cox wrote: > > On 31/05/2011, at 12:03 AM, julius wrote: > >> has the potential to create problems if it skips one's mind > > Well, so does almost anything in life. Coding's no different. > >> Of course I find decision to have NSArray count return NSUInteger s

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Scott Ribe
On May 30, 2011, at 7:31 AM, Roland King wrote: > No. I am saying that semantically the 'size' of an array is a non-negative > integer and thus the correct way to represent it is with a data type which > represents non-negative integers. While that is certainly correct, the counter argument is

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread julius
On 30 May 2011, Graham Cox wrote > > On 30/05/2011, at 9:03 PM, julius wrote: > >> Why did Cocoa developers make the count method return NSUInteger? > > > Because you can't have negative numbers of elements in an array. > > It's that simple. Yes but is that the only reason for doing this? >

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Roland King
.. going back on list .. On 30-May-2011, at 9:18 PM, julius wrote: > > On 30 May 2011, at 12:28, Roland King wrote: > >> >> >>> In what contexts is that output going to be used? >>> I think that like me people will tend to use it in contexts to do with >>> accessing array elements >>> e.g.

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Graham Cox
On 30/05/2011, at 9:03 PM, julius wrote: > Why did Cocoa developers make the count method return NSUInteger? Because you can't have negative numbers of elements in an array. It's that simple. The reason you're running into trouble is not because this type is unsigned, it's because you are do

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Roland King
> In what contexts is that output going to be used? > I think that like me people will tend to use it in contexts to do with > accessing array elements > e.g. x = [ary objectAtIndex:[ary count]-2]; well if you haven't already confirmed that [ary count ] can never be less than 2, or checked tha

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread jonat...@mugginsoft.com
On 30 May 2011, at 12:03, julius wrote: > > > So was it really just because the number of array elements is never -3 that > the Cocoa developers decided to make NSArray count return type NSUInteger? > > Julius > You always need to pay close close attention to function/method return types,

Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread julius
On Sun, 29 May 2011 18:15:10 -0400 > > From: Jeffrey Walton wrote > As Kyle said, its the C language - signed values are > promoted/converted (?) to unsigned. So -1 is always greater than 1 (if > you let it happen). Its really the generated CMP instruction which is > bitting you. Cast the unsign

Re: Why does NSArray count return NSUInteger?

2011-05-29 Thread Jeffrey Walton
On Sun, May 29, 2011 at 4:04 PM, julius wrote: > Hi, > I have just spent time investigating why > an if statement involving an [array count] was apparently misbehaving. > > The construct was this: >        if(3 < ([zAry count] - 10)) > It delivers a (to me unexpected) result when [zAry count] < 10

Re: Why does NSArray count return NSUInteger?

2011-05-29 Thread Siegfried
On 29/05/2011, at 17:13, Siegfried wrote: > > When one of the literals is unsigned, the other is implicitly converted, and > -1 is the highest int possible. I'm sorry, I mean operands instead of "literals"___ Cocoa-dev mailing list (Cocoa-dev@lists.

Re: Why does NSArray count return NSUInteger?

2011-05-29 Thread Kyle Sluder
On Sun, May 29, 2011 at 1:04 PM, julius wrote: > Hi, > I have just spent time investigating why > an if statement involving an [array count] was apparently misbehaving. > > The construct was this: >        if(3 < ([zAry count] - 10)) > It delivers a (to me unexpected) result when [zAry count] < 10

Re: Why does NSArray count return NSUInteger?

2011-05-29 Thread Siegfried
On 29/05/2011, at 17:04, julius wrote: > … > The reason is that [zAry count] returns a result of type NSUInteger Exactly. > … > Why might the Cocoa developers have chosen to do this? > … Not exactly Cocoa developers. In C, considering "uint" an unsigned int variable set to -1, a statement l

Re: Why does NSArray count return NSUInteger?

2011-05-29 Thread mlist0...@gmail.com
Maybe array indexes and counts are unsigned because you can't have a negative number of objects in an array? _murat On May 29, 2011, at 1:04 PM, julius wrote: > Hi, > I have just spent time investigating why > an if statement involving an [array count] was apparently misbehaving. > > The cons

Why does NSArray count return NSUInteger?

2011-05-29 Thread julius
Hi, I have just spent time investigating why an if statement involving an [array count] was apparently misbehaving. The construct was this: if(3 < ([zAry count] - 10)) It delivers a (to me unexpected) result when [zAry count] < 10. In fact if(3 >= ([zAry count] - 10)) also retur