Re: Sharing a global variable in Cocoa
Re: Sharing a global variable in Cocoa
- Subject: Re: Sharing a global variable in Cocoa
- From: Andy Lee <email@hidden>
- Date: Mon, 15 Apr 2002 10:04:26 -0400
At 3:34 PM +0200 4/15/02, Jesus De Meyer wrote:
how on earth do you share a varibale between several objects in
Cocoa. Each time I try to do this in a global.h file I get this
error: ...failed MasterObjectFile.Combine and then the path to
master.o
This is not so much a Cocoa question as a C question. You can
_declare_ a variable in your global.h as extern...
extern int foo; // announces that a variable "foo" of type int
// is defined somewhere
...and _define_ it in an implementation file (global.c, global.m,
global.mm, or whatever) without the extern keyword:
int foo; // allocates memory storage for the variable
You will get an error if you leave out the "extern" in global.h,
because the compiler will try to allocate the same variable twice if
global.h is included in multiple places.
--Andy
_______________________________________________
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.