Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Odd NSNumber PPC/Intel difference

Odd NSNumber PPC/Intel difference
Thread Tools
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jul 22, 2007, 10:00 PM
 
After a couple of beta testers found a weird behaviour in a new beta version of an application, I eventually tracked it down to the problem only occurring with PPC Macs, and then down to the following line of code:

if ( [[[thing amount] num2] floatValue] > 0.0 )

This worked fine on Intel Macs, but not on PPC Macs.
[[thing amount] num2] returns an NSNumber and the problem appears to occur when it returns nil. So a simple check for nil added to the logic fixed it completely, as shown below:

if ( [[thing amount] num2] && [[[thing amount] num2] floatValue] > 0.0 )

Surely this is absurd? Surely [<nil expression> floatValue] > 0.0 should always return NO/FALSE???? And therefore the addition should do nothing?

But I can assure you that in this case the addition fixes the problem completely.

Can anyone enlighten me as to why this behaviour occurs?
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jul 22, 2007, 10:05 PM
 
OK answered my own question, after further research.

Here's a discussion of the problem on the Cocoa mailing list... Cocoabuilder - (M. Carlson) Bug or feature?

Which led me to Apples official documentation of the behaviour: Universal Binary Programming Guidelines, Second Edition: Objective-C: Messages to nil

And I was naive enough to think that messages to a nil object would always return 0/nil/FALSE?
In short, that is only guarrenteed on Intel Macs, or if the message has an integer/object return type!
( Last edited by Brass; Jul 22, 2007 at 10:21 PM. )
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:26 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,