4.2 extern a DISASTER (Flame)

George Hart george at mnetor.UUCP
Thu Jul 18 01:01:03 AEST 1985


> An addendum to my previous note.  Dennis Ritchie has commented in this forum on
> the suitability of the strict interpretation of my last example.  In a
> nutshell, he said that it was a mistake to put it in the manual at all, and
> it was there for a single machine (Honeywell running GCOS) whose linker had
> arbitrary restrictions on the use of common symbols.  I'm not sure exactly
> what the ANSI (draft) standard says on this matter, as I don't have my copy
> handy.
> -- 
> 	Marty Shannon
> UUCP:	ihnp4!eagle!mjs
> Phone:	+1 201 522 6063

Excerpts from the 84 04 26 Draft ANSI C Standard.
(It seems as if the standard is saying the compilers which resolve
the variables in your last example to the same location are doing
it right!  Please correct me if I'm misinterpreting things.)

=============================

Section 7.2, "External data definition" 

  "A declaration of the identifier of an object with an initializer
   constitutes the DEFINITION of the object (i.e., that declaration for
   which the storage is allocated.

   A declaration of the identifier of an object without an initializer and
   -----------------------------------------------------------------------
   without the keyword "extern" constitutes a TENTATIVE DEFINITION.  If a
   ----------------------------------------------------------------------
   definition is encountered , all tenative definitions are taken to be
   --------------------------------------------------------------------
   declarations of the same object (subject to the linkage rules of
   ----------------------------------------------------------------
   Section 2.2.1).  If no subsequent definition is encountered, the first
   ----------------------------------------------------------------------
   tenative definition is taken to be a definition with initializer equal
   ---------------------------------------------------------------------
   to 0.
   -----

   A declaration of the identifier of an object without an initializer and
   with the keyword "extern" requires that somewhere in the entire program
   there must be exactly one definition for the identifier."


>From Section 2.2.1 "Scopes and linkages of identifiers"

   ...In the set of source files and libraries that constitutes an entire
   program, every instance of an identifier with external linkage denotes
	    -------------------------------------------------------------
   the same function or object....
   ----------------------------

   ...For an identifier of a function or object declared with file scope, if
   the lexically first declaration in the source file contains the keyword
   "static", the identifier has internal linkage.  Otherwise the
						   -------------
   identifier has external linkage....
   --------------------------------

==============================
-- 


Regards,

George Hart, Computer X Canada Ltd.
UUCP: {allegra|decvax|linus|ihnp4}!utzoo!mnetor!george
BELL: (416)475-8980



More information about the Comp.lang.c mailing list