Re: objective-c question/clarification
Re: objective-c question/clarification
- Subject: Re: objective-c question/clarification
- From: <email@hidden>
- Date: Mon, 25 Jun 2001 19:20:14 +1000 (EST)
On Mon, 25 Jun 2001 email@hidden wrote:
>
"InfoWindowController" is pointed at anything. Wouldn't
>
"InfoWindowController" always be nil thus allowing for the creation of
>
numerous "info windows" (which I know does not happen). I'm just curious
>
as to the mechanism behind this code, why it works.
Being declared static means only one instance of
_sharedInfoWindowController exists and it is maintained between calls to
the function. A simple example you can try to see this behaviour is:
#include <stdio.h>
void print_number(void) {
static int number = 0;
printf("%d\n", number);
++number; /* add 1 to number */
}
int main(void) {
int i;
for (i = 0; i < 10; ++i) {
print_number();
}
return(0);
}
print_number is called 10 times. If you remove the static keyword then
each time it prints 0. With static the value of number is "remembered"
between calls.
This is what's happeing in your ObjC case. The "= nil" only occurs the
very first time the function is called - every other time the previous
value is remembered.
Thanks,
Andrew