• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Basic Q: reading properties from nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic Q: reading properties from nil


  • Subject: Re: Basic Q: reading properties from nil
  • From: Rick Mann <email@hidden>
  • Date: Tue, 26 Oct 2010 14:33:11 -0700

On Oct 26, 2010, at 14:31:11, Nick Zitzmann wrote:

>
> On Oct 26, 2010, at 3:13 PM, Rick Mann wrote:
>
>> Hi. I've run into a bug, and I'm wondering if I'm expecting the wrong behavior. If I do this:
>>
>> UIWindow* win = nil;	//  In reality, it's coming from somewhere else, but it's nil
>> CGRect frame = win.bounds;
>>
>> Should I expect frame to be all zero? That's what I thought was the case, but I'm getting nonsense values that are not zero.
>
> No. The result is only zero if the primitive/structure size is a word or smaller. If it's larger, then the results are undefined. And CGRects contain four CGFloats, and CGFloats are 32-bit floats on iOS.
>
> So it's not a bug in the runtime. If you're running into the situation where a window can be nil, and you want to have a zeroed-out CGRect in that case, then do this:
>
> CGRect frame = (win ? win.bounds : CGRectZero);

Thanks Nick. I just discovered that exact information in the Objective-C manual. Sure seems like a conceptual inconsistency, but I guess whoever designed the language thought it was too expensive to return a zeroed struct.

Thanks for the confirmation!

--
Rick


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Basic Q: reading properties from nil
      • From: Greg Parker <email@hidden>
References: 
 >Basic Q: reading properties from nil (From: Rick Mann <email@hidden>)
 >Re: Basic Q: reading properties from nil (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Basic Q: reading properties from nil
  • Next by Date: Re: Basic Q: reading properties from nil
  • Previous by thread: Re: Basic Q: reading properties from nil
  • Next by thread: Re: Basic Q: reading properties from nil
  • Index(es):
    • Date
    • Thread