On Fri, Jul 11, 2008 at 8:10 PM, Greg <[EMAIL PROTECTED]> wrote:
> I've noticed that objects get initialized to nil if you don't set them, is
> this guaranteed in objective-c?
>
> I've been trying to find documentation from Apple on this but have been
> unable.
>
> In other words, if you have a simple class like this:
>
>> @interface MyClass : NSObject {
>>        id obj;
>> }
>> @end
>
> Then when -init is called is 'obj' *guaranteed*, always, in all versions of
> OS X, to be nil?

Yes, but that's because it's an instance variable. When memory for a
new object is allocated, its ivars are initialized to nil, 0, or 0.0
as appropriate.

On the other hand, local variables are *not* initialized:

-(void) foo {
    id obj;  // This can be anything
}

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to