|
-
September 18th, 2002, 03:30 AM
#1
Extern variable problem
Can anyone tell me if I can do the following:
Define a global variable in one cpp/c file (call it file1.c)
Then have it as an extern in a second file (call it file2.c),
but don't allow it to be changed from this file.
for example:
/****file1.c********/
double NiceVar;
void function()
{
NiceVar = 100; // I can set the value in file1.c easily.
}
/****************/
/****file2.c********/
extern double NiceVar;
void main()
{
NiceVar = 1000; // This shouldn't work.
printf( "%f", NiceVar ) // But this should return 100
}
/****************/
You'll have to excuse the basic explanation, but I am still a beginner!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|