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
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 mails | Author | Date |
|---|---|---|
| Wayne Shao | Aug 1, 20:43 | |
| Ken Thomases | Aug 1, 20:47 | |
| Clark S. Cox III | Aug 1, 20:54 | |
| Glenn English | Aug 1, 21:10 | |
| Jens Alfke | Aug 1, 21:18 | |
| Clark S. Cox III | Aug 1, 21:24 | |
| Arthur Coleman | Aug 1, 21:38 | |
| Clark Cox | Aug 1, 22:01 | |
| Giulio Cesare Sola… | Aug 1, 22:07 | |
| Clark S. Cox III | Aug 1, 22:15 | |
| Glenn English | Aug 1, 22:20 | |
| Michael Ash | Aug 1, 22:47 | |
| Sherm Pendley | Aug 1, 23:07 | |
| Daniel Staal | Aug 2, 00:27 | |
| Negm-Awad Amin | Aug 2, 09:05 | |
| Negm-Awad Amin | Aug 2, 09:09 | |
| mm w | Aug 2, 18:50 | |
| mm w | Aug 2, 20:19 | |
| Keary Suska | Aug 2, 22:53 | |
| Negm-Awad Amin | Aug 4, 08:31 |






Cocoa mail archive

