discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: +initialize and static (class) variables


From: Aurelien
Subject: Re: +initialize and static (class) variables
Date: Tue, 4 Sep 2001 19:30:57 +0200

Le mardi 4 septembre 2001, à 06:31, Richard Frith-Macdonald a écrit :

Well, the above code looks fine, and works for me.
The only unusual thing about 'advRequiredConstructors = [[NSArray alloc] initWithObjects: nil]' is that it is a varargs method ... so it does begin to sound as if you have compiler problems, or perhaps you picked up an incorrect stdarg.h/varargs.h when you built the libraries?

But then, the following should lead to the same problems:

NSLog ( @"Hello %s, it's now %d:%d", [[[NSString alloc] initWithString:@"Aurélien"] cString], 19, 0 );

It works though.

Here are some more empirical results:

thus declared is

static NSArray *advRequiredConstructors;

the following works:

+ initialize
{
  advRequiredConstructors = [NSArray array];
  <placeholder>
}

anything I add in the <placeholder> which involves advRequiredConstructors makes the program hang
e.g. [advRequiredConstructors addObject:@""]

More, if I try to send messages to the static object elsewhere, the program hangs too:

+ (Advertisement *) newAdvertisementWithType: (NSString *) advertisementType
{
  [advRequiredConstructors addObject:@""]; // this causes trouble !
  [...]
}

Now, something positive: if I make an NSString out of advRequiredConstructors:

static NSString *advRequiredConstructors;

and in + initialize:
{
  advRequiredConstructors = @"bubu"
}

When I call the following code from within my other static method:

NSLog ( @"the contents of the static variable is: %s", [advRequiredConstructors cString] );

then, I get rightly "the contents of the static variable is: bubu"

Looks like a bug in NSArray to me !

:-( strange, isn't it :-|

Aurélien



reply via email to

[Prev in Thread] Current Thread [Next in Thread]