Re: pointers in objective-c?
Re: pointers in objective-c?
- Subject: Re: pointers in objective-c?
- From: "Sherm Pendley" <email@hidden>
- Date: Fri, 1 Aug 2008 17:07:57 -0400
On Fri, Aug 1, 2008 at 3:38 PM, Arthur Coleman <email@hidden> wrote:
> I hate to be dense, but what about C structs like NSRect?
There's nothing special about them - they can be allocated on the
stack or on the heap, just like any other C struct.
> There are initialized on the stack aren't they?
Unlike instance variables, which are initialized to 0, 0.0, or nil,
when an object is allocated, stack variables are *not* initialized to
any particular value. That's why it's a good idea to initialize them
yourself when you declare them:
-(void)foo {
id bar = nil;
id baz;
// Do stuff
}
In the above, bar will always be nil when you get to the "Do stuff"
code. But the value of baz will be whatever happened to be at that
location on the stack before you called -foo.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
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