State of instance variables defined at instantiation?
State of instance variables defined at instantiation?
- Subject: State of instance variables defined at instantiation?
- From: Greg Hurrell <email@hidden>
- Date: Tue, 27 May 2003 03:04:32 +0930
I've checked my Cocoa book, the list archives etc, and I want to know:
Is the state of instance variables inside an object defined at
instantiation time?
Testing shows that pointers to objective-c objects are nil, and ints
are 0 etc.
But I want to know if I can always depend on this... ie. is it defined
behaviour?
For the sake of comparison, in C++ the state of member variables at the
time of instantiation is officially "undefined".
Sample case:
@interface MYObject : NSObject {
NSMutableString *stringValue;
int intValue;
}
@end
@implementation MYObject
- (id)init
{
self = [super init];
// Testing shows that currently (Mac OS X 10.2.6):
// the state of stringValue is nil
// the state of intValue is 0
// but can I assume this will always be true in the future?
// should I also be doing?:
stringValue = nil;
intValue = 0;
return self;
}
@end
Thanks for the tips from anyone old, wise and informed enough to know.
Cheers
Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.