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: Richard Frith-Macdonald
Subject: Re: +initialize and static (class) variables
Date: Tue, 4 Sep 2001 17:49:23 +0000

On Tuesday, September 4, 2001, at 05:30 PM, Aurelien wrote:


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 );

Or perhaps other problems entirely :-)

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:@""]

Well, that *should* raise an exception since NSArray does not respond to addObject:
However, legitamete methods of NSArray should work fine there.

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

If you used [NSArray array] to initialise the variable, you should have got a warning about a memory leak ... unless you had an autorelease pool. If there was an autorelease pool in place, the array may have been released before you got round to sending messages to it -
which would result in an exception or a crash.

Sounds like you need to step through this in gdb and find out what's really happening. The fact that it all works fine when I run your code snippets on my system suggests that either you have a compiler problem, or something elsewhere in your program is messing things up (eg scribbling over memmory it shouldn't be touching). That's really impossible
for me to check without having the entire program to run under debug.



reply via email to

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