use of extern keyword
-
Hi! I am working on MFC SDI application. can anybody tell me any good example of using extern keyword. can extern be used for passing value of any string variable from one class to another. If it can be used, then how? thanx
**swaapu says:**can extern be used for passing value of any string variable from one class to another? No it is not possiable using extern. extern is for different purpose. if you want to declare later and but if you want to use before itself then use key word extern. Nice talking to you. :-O
-
Hi! I am working on MFC SDI application. can anybody tell me any good example of using extern keyword. can extern be used for passing value of any string variable from one class to another. If it can be used, then how? thanx
Hello, The extern keyword is used to say to the compiler that you are using a variable declared in another translation unit. See the following for example: You have one translation unit where you define your variable
// file1.cpp
int g_nSomeInt = 0;And another one where you want to use the variable
// file2.cpp
extern int g_nSomeInt;void DoFoo()
{
g_nSomeInt++;
}This is how extern can be used. It is adviced though too use accessor functions instead of the extern keyword. Behind every great black man... ... is the police. - Conspiracy brother Blog[^]
-
Hi! I am working on MFC SDI application. can anybody tell me any good example of using extern keyword. can extern be used for passing value of any string variable from one class to another. If it can be used, then how? thanx
The extern keyword simply states that the variable or function is declared in a seperate translational unit. That is it is declared and defined in a seperate file from the one that depends on it. Declaring a function prototype as external, only serves to inform the coder that it is declared and defined in another file. Defining a variable as external, informs the complire that it is declared and defined golobaly in another file. The difference between a function protype and a global variable, is that a global variable must be declared external and a prototype is external by default. I've workd with C code that required alot on global variables (dealing with hardware specific addresses). In that case a file was set off to the side to define all the hardware specific data (global variables), which needed to be declared as extern. INTP Every thing is relative...