Re: how to check if a property is empty?
Re: how to check if a property is empty?
- Subject: Re: how to check if a property is empty?
- From: Jens Alfke <email@hidden>
- Date: Sat, 29 Mar 2008 10:22:34 -0700
On 29 Mar '08, at 10:11 AM, Davide Benini wrote:
I half suspected something like this...
Well, for a _pointer_ type*, there is an "empty" value: NULL. (For
object pointers the constant 'nil' is used, but they both have the
same underlying value.)
When an Objective-C object is created, its storage is filled with
zeroes. So instance variables that you haven't assigned a value to yet
are guaranteed to be NULL, or nil, or zero. (In other words, Objective-
C's 'alloc' calls 'calloc', not 'malloc'.)
But watch out — this doesn't apply to local variables in functions or
methods. Those have random/garbage values until initialized. Same goes
for raw memory allocated via 'malloc' — use 'calloc' if you want it
zeroed.
—Jens
* It sounds like you're coming from a PHP background ... if you
haven't done much C programming before, the distinction between
pointers and scalars is likely to be confusing, since it doesn't exist
in higher-level languages. If so, definitely find a good C textbook
and read through that first!Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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