Skip navigation.
 
mlRe: pointers in objective-c?
FROM : Sherm Pendley
DATE : Fri Aug 01 23:07:57 2008

On Fri, Aug 1, 2008 at 3:38 PM, Arthur Coleman <<email_removed>> 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

Related mailsAuthorDate
mlpointers in objective-c? Wayne Shao Aug 1, 20:43
mlRe: pointers in objective-c? Ken Thomases Aug 1, 20:47
mlRe: pointers in objective-c? Clark S. Cox III Aug 1, 20:54
mlRe: pointers in objective-c? Glenn English Aug 1, 21:10
mlRe: pointers in objective-c? Jens Alfke Aug 1, 21:18
mlRe: pointers in objective-c? Clark S. Cox III Aug 1, 21:24
mlRe: pointers in objective-c? Arthur Coleman Aug 1, 21:38
mlRe: pointers in objective-c? Clark Cox Aug 1, 22:01
mlRe: pointers in objective-c? Giulio Cesare Sola… Aug 1, 22:07
mlRe: pointers in objective-c? Clark S. Cox III Aug 1, 22:15
mlRe: pointers in objective-c? Glenn English Aug 1, 22:20
mlRe: pointers in objective-c? Michael Ash Aug 1, 22:47
mlRe: pointers in objective-c? Sherm Pendley Aug 1, 23:07
mlRe: pointers in objective-c? Daniel Staal Aug 2, 00:27
mlRe: pointers in objective-c? Negm-Awad Amin Aug 2, 09:05
mlRe: pointers in objective-c? Negm-Awad Amin Aug 2, 09:09
mlRe: pointers in objective-c? mm w Aug 2, 18:50
mlRe: pointers in objective-c? mm w Aug 2, 20:19
mlRe: pointers in objective-c? Keary Suska Aug 2, 22:53
mlRe: pointers in objective-c? Negm-Awad Amin Aug 4, 08:31