|
-
Aug 7th, 2002, 03:13 PM
#1
Thread Starter
Fanatic Member
extern
must we always do
extern int a;
when declaring and not defining in C++?

prog_tom
JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
http://physics.sviesoft.com/forum
-
Aug 7th, 2002, 03:17 PM
#2
Ya ya Baby!!!Me is Back
Do not use extern all the time. You need it only in some case that you do not have to define it but only to declare the variable.
-
Aug 7th, 2002, 03:18 PM
#3
Thread Starter
Fanatic Member
Would you like to post a situation like that please?

prog_tom
JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
http://physics.sviesoft.com/forum
-
Aug 7th, 2002, 03:29 PM
#4
Frenzied Member
Code:
// in source file A
unsigned long x;
Code:
// in source file B
extern unsigned long x;
...
x = 10;
The extern keyword in the variable declaration means that we are NOT declaring the variable here, but that it is declared somewhere else. The compiler says, Ok, and happily compiles, and leaves it to the linker to find the variable it should be pointing to.
Z.
-
Aug 7th, 2002, 07:40 PM
#5
Frenzied Member
But.
It has to be a global variable.
ie., it is not defined inside any function, including main();
-
Aug 7th, 2002, 08:24 PM
#6
Thread Starter
Fanatic Member
does that mean whenever I defining a extern, unsigned variable, I always have to define it outside any function?

prog_tom
JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
http://physics.sviesoft.com/forum
-
Aug 7th, 2002, 10:59 PM
#7
PowerPoster
Originally posted by prog_tom
does that mean whenever I defining a extern, unsigned variable, I always have to define it outside any function?
I don't think so. But the actual variable you want to use should be global.
So this one should be global if you want to use extern:
Where this one can be anywhere as long you follow the above rule(I think):
PHP Code:
extern int myvar;
-
Aug 8th, 2002, 09:26 AM
#8
Frenzied Member
No. It should be global as well in the sub-module.
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
|