Re: Frameworks and global variables
Re: Frameworks and global variables
- Subject: Re: Frameworks and global variables
- From: Chris Kane <email@hidden>
- Date: Sat, 14 Jul 2001 11:26:47 -0700
On Thursday, July 12, 2001, at 08:23 AM, Christian Mike wrote:
I am trying to access a global variable defined in a framework from an
application. For example, I have a simple Cocoa framework that contains:
char *string[] = "Some String";
long value = 1234;
void Frame1Routine()
{
NSLog(@"Frame 1 message");
// code and stuff
}
Now in my application, I have added the framework to the project. I know
that the framework is getting included properly, because I can call
Frame1Routine from my application, and the NSLog message is printed.
Now, if within my application I declare:
extern char *string;
extern long value;
and try to reference them from my application, it crashes with:
FinalApp.app has exited due to signal 11 (SIGSEGV).
In fact that same error happens even if I try to access those "global"
variables from within the Frame1Routine!
The fact that you can link the program and get to the point of running
it where it then crashes shows that you are able to access the framework
globals from the app.
As I'm sure other people are pointing out in mail messages of their own
at this moment, this guy:
char *string[] = "Some String";
is mis-declared. You're declaring a pointer to an array of characters,
which is one too many indirections. Do either "char *string" or "char
string[]". The former is more conventional in C.
Chris Kane
Cocoa Frameworks, Apple