> From: Aravindhan Krishnan <[EMAIL PROTECTED]>
> 
> Whats the difference between the following declarations.?
> 
> //file 1
> extern int x=8;
> 
> // file 2
> extern int x;
> 
>   (AND)
> 
> 
>  //file 1
> int x=8;
> 
> // file 2
> extern int x;
> 
> Thanks,
> Aravindhan
> 
> 

The keyword 'extern' specifies to the compiler that,
the variable 'x' will be found in the symbol table
of another translation unit.

In short, memory is *not* allocated for the variable
with 'extern' storage specifier in that translation unit.

Having said that, please note that extern declaration is
resolved by the linker and not the compiler !

Let's discuss your examples now.

Illustration1:
 . file1 : memory for x declared elsewhere
 . file2 : memory for x declared elsewhere
 perhaps you have a header file that defined x.
 since x=8 in file 1, the variable 'x' has been promoted into
 the symbol table of translation unit ie. file1.

Illustration2:
 . file1: variable 'x' declared
          4 bytes of memory allocated for variable x
          variable 'x' is in the symbol table of translation unit 
          ie. file1
 . file2: memory for 'x' declared elsewhere
          since externs are always global value '8' seen for x.

Hope this helps.


thanks
Saifi.

Reply via email to