Re: Universal Binaries and messages to nil
Re: Universal Binaries and messages to nil
- Subject: Re: Universal Binaries and messages to nil
- From: Keith Blount <email@hidden>
- Date: Sun, 5 Feb 2006 14:39:39 -0800 (PST)
Thanks for the swift replies. This is what I feared -
I'm not sure how I got into this bad habit, I think it
was just when I didn't get errors when assuming return
values for dictionaries when starting out with Cocoa.
Oops.
Glenn - thanks, yes, -floatForKey: would be a better
option with NSUserDefaults. It tends to be with
dictionaries that I use this as much as user defaults,
though, so in those cases I guess I just need the
extra check.
Right, tomorrow is going to be spent going through my
code and fixing this. It's a good job I'm still only
at a closed beta stage...
Thanks again,
Keith
--- Jim Correia <email@hidden> wrote:
> On Feb 5, 2006, at 5:04 PM, Keith Blount wrote:
>
> > Currently, I often lazily rely on a message to
> (what
> > should be) an NSNumber returning zero if the
> NSNumber
> > is actually nil, especially when dealing with user
> > defaults, as in the following example:
> >
> > float marginWidth = [[[NSUserDefaults
> > standardUserDefaults]
> objectForKey:@"SCRMarginWidth"]
> > floatValue];
>
> You are already living on borrowed time and need to
> fix your code for
> PPC today.
>
> > I believe that on Intel, this could cause problems
> if
> > no value existed for "SCRMarginWidth", and I were
> > therefore calling -floatValue on nil. (Though this
> > wouldn't be a problem if I were calling -boolValue
> or
> > -intValue, correct?)
>
> This code is already wrong on PowerPC.
>
> The documentation says:
>
>
<http://developer.apple.com/documentation/MacOSX/Conceptual/
>
>
universal_binary/universal_binary_tips/chapter_5_section_22.html>
>
> > Objective-C, it is valid to send a message to a
> nil object. The
> > Objective-C runtime assumes that the return value
> of a message sent
> > to a nil object is nil, as long as the message
> returns an object or
> > any integer scalar of size less than or equal to
> sizeof(void*).
> This is the only universal, documented truth that
> holds across
> architectures. Because floating point values are
> returned via a
> different register on PPC than integer values, if
> the object is nil
> you are going to get back a garbage value on PPC.
>
> Jim
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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