question about scope & linkage
Conor P. Cahill
cpcahil at virtech.UUCP
Fri Aug 11 10:15:58 AEST 1989
In article <57257 at tut.cis.ohio-state.edu>, cml at giza.cis.ohio-state.edu (Christopher Lott) writes:
>
> I am asking about the scope and declaration of a variable; I have
> read K&Rv2, p. 227-228, Scope and Linkage, but can't seem to dig out
> the answer. (what is a 'translation unit' ??)
>
1. I believe a translation unit is a .c file.
2. Definitions of global data elements:
real definition: a declaration with an initialization
tentative definition: a declaration without an initialization
A global symbol may have unlimited tentative definitions, but only 1 real
definition. In other words, you can have "int i;" in every .c and they
will all refer to the same data space. You can even have "int i=3;" in
one (but only one) of the source files and they will still refer to the
same data space. But if you have more than one "int i=2;", even if you
set the initial value to the same value, the loader (ld) will complain
about multipley defined symbols.
More information about the Comp.lang.c
mailing list