A question about tenative definitions
Stanley Friesen
sarima at tdatirv.UUCP
Wed Mar 6 06:13:13 AEST 1991
In article <4218 at lupine.NCD.COM> rfg at lupine.ncd.com (Ron Guilmette) writes:
>I'm having a discussion with a C implementor I know about the meaning of
>the following sentence from the ANSI C standard.
> "If a translation unit contains one or more tenative definitions
> for an identifier, and the translation unit contains no external
> definition for that identifier, then the behavior is exactly as
> if the translation unit contains a file scope declaration of that
> identifier, with a composite type as of the end of the translation
> unit, with an initializer equal to zero."
>
>What exactly does this mean? ...
< Example consisting of two translation units (=files) deleted>
>... if you compiled them both and then tried to link them together into
>the same single program, that you should get an error at link time because
>there are two conflicting external *definitions* of the variable xxyyzz.
>
>This implementor I know disagrees with my interpretation.
>
>Who is right?
In essence you are right. The example you gave generates what ANSI calls
'undefined behavior'. This means that it is *not* a conforming C program.
It also, generally, means that *any* behavior on the part of the system is
acceptable. So, this *may* mean that the implementor's approach is a legal
local *extension* to ANSI C. Of course any programs that depend on such an
extension will not be portable. [It is a legal extension as long as the
ANSI standard does not *require* a diagnostic for this error; I do not
believe it does, so the extension is likely to be legal].
The whole matter is discussed in some detail in the rationale document.
--
---------------
uunet!tdatirv!sarima (Stanley Friesen)
More information about the Comp.std.c
mailing list