Type comparison warning

2008-10-30 Thread DKJ
I'm probably missing something simple, but I don't understand why this  
line:


return (i == -1 ? [NSNull null] : [NSNumber numberWithInteger:i]);

(where i is an NSInteger) produces this warning:

comparison of distinct Objective-C types lacks a cast

(The return type of the method is id.)

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Type comparison warning

2008-10-30 Thread Dave Carrigan


On Oct 30, 2008, at 10:12 AM, DKJ wrote:

I'm probably missing something simple, but I don't understand why  
this line:


return (i == -1 ? [NSNull null] : [NSNumber numberWithInteger:i]);

(where i is an NSInteger) produces this warning:

comparison of distinct Objective-C types lacks a cast

(The return type of the method is id.)



The ternary conditional operator requires that both sides of the : are  
the same type. In your case, one is a NSNull* and one is a NSNumber*,  
and C has no idea that a NSNull* and a NSNumber* are in any way the  
same kind of pointer, which means that it has no idea what the type of  
the overall statement is. This would compile:


  return (i == -1 ? (id)[NSNull null] : (id)[NSNumber  
numberWithInteger:i]);


--
Dave Carrigan
[EMAIL PROTECTED]
Seattle, WA, USA



PGP.sig
Description: This is a digitally signed message part
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Re: Type comparison warning

2008-10-30 Thread Scott Ribe
First off, NSInteger is an object not an int and can't be directly compared
to an int. Second, i is not likely an NSInteger, it's a pointer to an
NSInteger, which means it can be compared to an int, via implicit or
explicit casting, but in the absence of an explicit cast, the compiler
assumes that's probably not what you intended to do.

Next, NSNull  NSNumber are distinct types; the ternary operator wants both
potential returns to be of the same type (or compatible types for some
meaning of compatible), so the compiler will warn you about that once you
fix the first problem. Just cast both to id and you'll be fine--assuming the
code that receives this id properly handles the fact that it may point to
different types.

I started to say this is all basic C stuff, but that's not quite fair. It's
the intersection of Objective-C extensions with the basic C rules, which
still hold true.


-- 
Scott Ribe
[EMAIL PROTECTED]
http://www.killerbytes.com/
(303) 722-0567 voice


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Type comparison warning

2008-10-30 Thread Clark Cox
On Thu, Oct 30, 2008 at 10:47 AM, Scott Ribe [EMAIL PROTECTED] wrote:
 First off, NSInteger is an object not an int and can't be directly compared
 to an int.

Not true, NSInteger and NSUInteger are typedefs for plain integer
types, *not* Objective-C objects.

-- 
Clark S. Cox III
[EMAIL PROTECTED]
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Type comparison warning

2008-10-30 Thread Scott Ribe
 Not true, NSInteger and NSUInteger are typedefs for plain integer
 types, *not* Objective-C objects.

Yes, yes, yes. Thanks for pointing that out. I'm not doing 10.5-only
development yet, so I read NSNumber because I'm not used to seeing
NSInteger anywhere.

-- 
Scott Ribe
[EMAIL PROTECTED]
http://www.killerbytes.com/
(303) 722-0567 voice


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Type comparison warning

2008-10-30 Thread Jean-Daniel Dupas


Le 30 oct. 08 à 19:01, Scott Ribe a écrit :


Not true, NSInteger and NSUInteger are typedefs for plain integer
types, *not* Objective-C objects.


Yes, yes, yes. Thanks for pointing that out. I'm not doing 10.5-only
development yet, so I read NSNumber because I'm not used to seeing
NSInteger anywhere.


NSInteger can safely be used for developpement that target any OS 10  
version (it is binary compatible with previous OS X version).


All my projects that target 10.4 already use NSInteger (and are 64  
bits safe).


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Type comparison warning

2008-10-30 Thread Scott Ribe
 All my projects that target 10.4 already use NSInteger (and are 64
 bits safe).

I got an error when I first tried. Perhaps that was with a project that
still supports 10.3.9...

-- 
Scott Ribe
[EMAIL PROTECTED]
http://www.killerbytes.com/
(303) 722-0567 voice


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Type comparison warning

2008-10-30 Thread Nick Zitzmann


On Oct 30, 2008, at 6:03 PM, Scott Ribe wrote:

I got an error when I first tried. Perhaps that was with a project  
that

still supports 10.3.9...



If you're using an older SDK, then you can support NS(U)Integer and  
CGFloat in your older code just by copying the definitions from the  
Leopard SDK, taking out all of the 64-bit code (__LP64__), and putting  
the definitions in a place where they will be loaded _after_ the  
Foundation framework headers but _before_ your own code. This will  
help you get ready for 64-bit development when you're ready to take  
the plunge.


Nick Zitzmann
http://www.chronosnet.com/

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]