🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4159

Tentative definitions

#4159
From: Konrad Schwarz
Date: Mon, 02 Oct 1995 19:16
59 lines
2651 bytes
An older version of Microsoft C does not make ``i'' have external linkage
in the following code:

extern int i;
int i;

``i'' has external linkage when initialized, e.g.,

extern int i;
int i = 0;

The ANSI C Standard, as included in H. Schildts book, says:
``6.7.2: Semantics: If the declaration of an identifier for an object
has file scope and an initializer, the declaration is an external definition for
the identifier.''

This is consistent with the second example (I think).

Section 6.1.2.2, 4th paragraph:
``If the declaration of an identifier for an object or a fuction contains
the storage-class specifier extern, the identifier has the same linkage as any
visible declaration of the identifier with file scope.  If there is no visible
declaration with file scope and no storage-class specifier, its linkage is
external.''

What does visible declaration mean?  I think it means a declaration that
has not been overlaid by a block scoped identifier.  Thus,
``extern int i;'' should have the linkage of ``int i;''.

Section 6.7.2 2nd paragraph:

``A declaration of an identifier for an object that has file scope without an
initializer, and without a storage-class specifier or [...], constitutes a
tentative definition.  If a translation unit contains one or more tentative
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
the composite type as of the end of the translation unit, with an initializer
equal to 0.''

Does imply that file scope declarations of objects without external
definitions have internal linkage?

Section 6.7 says (Semantics, 2nd paragraph):
``An external definition is an external declaration that is also a definition
of a function or an object.''

Does this together with the first quote mean that to define an object with
external linkage in ANSI C, you must initialize it?
Is there any way of making objects have external linkage without initializing
them?

Do not feel bound by the questions.  I appreciate any insights into the topic
you may have.
 
Thank you
Konrad Schwarz

PS: if email to this account bounces, use e8626196@fbma.tuwien.ac.at
Technical Details
Message-ID: <44pdr1$378@news.tuwien.ac.at>
Path: arc1-ca.pugleaf.net!mips.complang.tuwien.ac.at!schwarz

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mips.complang.tuwien.ac.at!schwarz
From: schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz)
Newsgroups: comp.std.c
Subject: Tentative definitions
Date: 2 Oct 1995 19:16:49 GMT
Organization: TU Wien
Message-ID: <44pdr1$378@news.tuwien.ac.at>
NNTP-Posting-Host: mips.complang.tuwien.ac.at
Keywords: external linkage