question about scope & linkage
Conor P. Cahill
cpcahil at virtech.UUCP
Sat Aug 12 11:13:43 AEST 1989
In article <14270 at haddock.ima.isc.com>, karl at haddock.ima.isc.com (Karl Heuer) writes:
> In article <1001 at virtech.UUCP> cpcahil at virtech.UUCP (Conor P. Cahill) writes:
> >[Stuff about real vs. tentative definitions] A global symbol may have
> >unlimited tentative definitions, but only 1 real definition.
>
> I think you're confusing tentative definitions with non-defining declarations.
I am not.
>
> >In other words, you can have "int i;" in every .c and they will all refer to
> >the same data space.
>
> This is not correct. A tentative definition retroactively becomes a real
> definition if the end of the source file is reached without seeing a real
> definition. The purpose of the tentative-definition nonsense is not to force
> the Common-block storage model to work; it's to allow forward reference to
> non-global identifiers.
>
A tentative definition of a data object is not resolved at the end of source
module, but at link time. I quote from K&R2 pg 227,
...In the alternate formulation, which is usual in UNIX systems and
recognized as a common extension by the Standard, all tentative
definitions for an externally linked object, throughout ALL the
translation units of a program are cosidered together instead of
in each translation unit separately. If a definition occurs somewhere
in the program, then the tentative definitions become merely
declarations, but if no definition appears, then all its tentative
definitions become a definition with initializer 0.
"tentative definition" is defined as "an external object declaration that
does not have an initializer, and does not contain the extern specifier"
Therefore what I said is absolutely correct. BTW, I don't see how any of
this applies to a "forward reference to non-global identifiers".
More information about the Comp.lang.c
mailing list