Re: Universal Binaries and messages to nil
Re: Universal Binaries and messages to nil
- Subject: Re: Universal Binaries and messages to nil
- From: Jim Correia <email@hidden>
- Date: Sun, 5 Feb 2006 17:14:57 -0500
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 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