• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
State of instance variables defined at instantiation?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: State of instance variables defined at instantiation?
      • From: Ben Dougall <email@hidden>
    • Re: State of instance variables defined at instantiation?
      • From: Piers Uso Walter <email@hidden>
  • Prev by Date: Re: Geometric computation software
  • Next by Date: Re: State of instance variables defined at instantiation?
  • Previous by thread: Re: NSPreferences, etc.
  • Next by thread: Re: State of instance variables defined at instantiation?
  • Index(es):
    • Date
    • Thread