FROM : Jens Alfke
DATE : Sat Mar 29 18:22:34 2008
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!
DATE : Sat Mar 29 18:22:34 2008
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!
| Related mails | Author | Date |
|---|---|---|
| Davide Benini | Mar 29, 16:32 | |
| Quincey Morris | Mar 29, 18:04 | |
| Davide Benini | Mar 29, 18:11 | |
| Jens Alfke | Mar 29, 18:16 | |
| Jens Alfke | Mar 29, 18:22 |






Cocoa mail archive

