Problem 1What
is the difference between the declaration and the definition of a
symbol?
Answer:
The declaration
of a symbol tells the compiler what kind of symbol it is. This allows
the compiler to generate code that correctly accesses the symbol.
The definition
of a symbol actually allocates space for and defines the contents
of the symbol.
The difference
is important when you are building a project from separately-compiled
modules that need to share data and subroutines. Each shared item
should be declared wherever it is used, but defined only once.
For example,
in C, you might put the declaration
extern int debug_flag;
in an include file
used by all modules that need to access debug_flag. However,
only one source file will contain the definition:
int debug_flag = 0;
Contributor:
Naveen P N
8-01
NEXT Q&A
|