Click to See Complete Forum and Search --> : extern sample in MSDN


George2
February 11th, 2008, 12:42 AM
Hello everyone,


I think in practical experience, extern is useful only when we have more than one compile unit (cpp file) and making cross-reference between compile units.

In the MSDN extern sample,

http://msdn2.microsoft.com/en-us/library/0603949d.aspx

It only uses one source file (compile unit) to demonstrate the usage of extern, is it correct and practical?


thanks in advance,
George

laserlight
February 11th, 2008, 01:47 AM
In the MSDN extern sample,
There are two code examples in that MSDN entry.

It only uses one source file (compile unit) to demonstrate the usage of extern, is it correct and practical?
What do you mean by "practical"? Code examples are typically not "practical", but intended either for demonstration or to be adapted for actual use.

George2
February 11th, 2008, 03:28 AM
Thanks laserlight,


I mean this sample. Any comments to my original question?


// specifying_linkage1.cpp
int i = 1;
void other();

int main() {
// Reference to i, defined above:
extern int i;
}

void other() {
// Address of global i assigned to pointer variable:
static int *external_i = &i;

// i will be redefined; global i no longer visible:
// int i = 16;
}


There are two code examples in that MSDN entry.


What do you mean by "practical"? Code examples are typically not "practical", but intended either for demonstration or to be adapted for actual use.


regards,
George