Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C ---- external variables

Status
Not open for further replies.

archit

Programmer
Aug 22, 2002
19
US
Where are the external variables stored in C lang.
 
External variables of a C object file are global variables of another object file.

When all needed object files, either true object file (.o) or object files stored in libraries (.a or .so or ....) are linked together to create an executable, there is no more external variables but only global variables of all the needed objects.

Note that when linking to create an executable using a C compiler, some libraries are silently added (libC.a and others maybe) containing commonly used "external" variables like (stdin, stdout, stderr, errno ...).

If some external variables are not found in any object file, the linker failed to create an executable.
 
dchoulette's description is accurate.

If you want to see some more examples open the /usr/include/stdio.h file. And check out the definitions of file operations.printfs etc.
e.g.(from stdio.h)
extern FILE *fopen(const char *, const char *);
extern FILE *freopen(const char *, const char *, FILE *);

When you include a header file you also include the extern defintion. When the file is compiled with the C-library the extern defintions are resolved by the global variables/functions present in the C-library.

cheers
amit
crazy_indian@lycos.com

to bug is human to debug devine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top