Linkers, Loaders & Executables
In C, what does writing "extern int count;" mean?
- AIt declares that a variable count is defined somewhere else and reserves no storage here
- BIt creates a new variable count initialized to 0
- CIt hides the variable count from outside this file
Show answer and explanation
Answer: A. It declares that a variable count is defined somewhere else and reserves no storage here
extern declares "a variable with this name is defined in another file" and reserves no memory. The compiler emits instructions referring to count without knowing its address and records that place in the relocation entries. The linker binds it to a definition such as "int count = 0;" in another file and fixes the address. The usual practice is to put extern declarations in a header and the definition in exactly one source file.
- A. Correct. It is only a declaration; the definition is elsewhere.
- B. Storage is reserved by a definition such as "int count;".
- C. Hiding from other files is static.