🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1550

Re: incomplete types/tentative definitions

#1550
From: Doug Gwyn
Date: Wed, 01 Aug 1990 21:12
28 lines
2063 bytes
In article <41187@think.Think.COM> simons@think.com (Joshua Simons) writes:
>int a[] ;
>3.7.2 seems to say that this is a tentative definition and that it
>should be treated as if it has an 'initializer equal to 0'.

More importantly, it's an incomplete type that must be completed by
the end of the translation unit.  If no initializer is given for the
declaration that completes the type, nor for any other external
declaration of the same (file-scope) object, assuming they all lacked
the "extern" storage-class specifier, then all the declarations were
tentative definitions, and in effect at the end of the translation
unit an external (composite-type) definition for the object is created
by the compiler and 0s are supplied as initial values.

>Intuitively, I would think that my original should be equivalent to:
>extern int a[] ;
>That is, it isn't a tentative definition...it is just a declaration
>which references something in another compilation unit. But I can't
>figure out how to read the Standard to get that interpretation.

Nope.  A file-scope declaration doesn't become an external reference
merely because it has incomplete type.  I think you're thinking of the
"common" model for external objects, as implemented in earlier UNIX C
compilers; however, the Standard requires a def/ref model, as specified
in K&R 1st Edition.  This is a case where X3J11 backed implementors
who had followed the de facto language standard (K&R Appendix A) rather
than the UNIX implementation.  (Forbidding macro argument substitution
within string literals etc. was another such case.)
Technical Details
Message-ID: <13467@smoke.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn
References: <41187@think.Think.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn
From: gwyn@smoke.BRL.MIL (Doug Gwyn)
Newsgroups: comp.std.c
Subject: Re: incomplete types/tentative definitions
Message-ID: <13467@smoke.BRL.MIL>
Date: 1 Aug 90 21:12:57 GMT
References: <41187@think.Think.COM>
Organization: U.S. Army Ballistic Research Laboratory, APG, MD.
Lines: 28