incomplete types/tentative definitions

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Aug 2 07:12:57 AEST 1990


In article <41187 at think.Think.COM> simons at 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.)



More information about the Comp.std.c mailing list