Re: Definition of Nil and nil was: NSData testing for NULL [SOLVED]
Re: Definition of Nil and nil was: NSData testing for NULL [SOLVED]
- Subject: Re: Definition of Nil and nil was: NSData testing for NULL [SOLVED]
- From: Guy English <email@hidden>
- Date: Mon, 17 Jan 2005 10:15:29 -0500
On Mon, 17 Jan 2005 08:22:08 -0500, Mark Ritchie <email@hidden>
> On Jan 17, 2005, at 2:16 AM, Robin Hermann wrote:
> > Can't find very much info (Apple Docs, Google) on NULL, Nil and nil
> > though.
> The handy thing about nil is that you can legally send messages to nil
> in Objective-C.
> [nil someMethodName] is quite legal and in fact, relied upon regularly.
While this is true there are a couple of gotchas to it. Sending a
message to nil will return you a 0 in the standard function return
register. This sounds nice until you call a method that returns a
float (returned in a float register) or a structure (on the stack).
So [nil intValue] will work fine and return 0 (or nil if you're
expecting and object, NO for a boolean). But "[nil floatValue]" or
"[nil frame]" will fail and you'll get an undetermined result - the
garbage that's either on the stack or sitting in the float register at
the time. I'm just pointing this out because it's an annoying bug to
track down if you're assuming that messaging nil will do the right
thing in all cases.
Guy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden