A question about tenative definitions

Ron Guilmette rfg at NCD.COM
Tue Mar 5 06:36:53 AEST 1991


In article <1807 at svin02.info.win.tue.nl> debra at info.win.tue.nl writes:
+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...
+>[ description of tentative definition deleted ]
+>What exactly does this mean?  My off-the-cuff interpretation of this
+>statement was that if you had two files like:
+>... [ example deleted ]
+>and 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.
+
+Nope, you are wrong.
+int xxyyzz; int xxyyzz; int xxyyzz;
+may be repeated as often as you like, as they are "tentative" definitions.
+you may have several (non-conflicting) tentative definitions of the same
+variable.
+A true (non-tentative) definition is one with initialization.
+you may write int xxyyzz=1; only once.
+if none of the (tentative) definitions has an initializer then the
+variable will be initialized with 0.

Paul, I think that you missed my point entirely.  I know that you are
right that I can put:

	int xxyyzz; int xxyyzz; int xxyyzz;

as many times as I like in ONE COMPILATION UNIT, but look again at the
exact wording from 3.7.2:

	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 an initializer equal to zero.

Now that suggests to me that the following two "translation units" should
be treated (by the compiler and assembler and linker) as being EXACTLY
identical to one another:

	version1.c:
	--------------------------------------------------------------------
	int xxyyz;
	int xxyyz;
	int xxyyz;
	--------------------------------------------------------------------

	version2.c:
	--------------------------------------------------------------------
	int xxyyz = 0;
	--------------------------------------------------------------------

Now if that is true, i.e. if the two translation units about are supposed
to be treated EXACTLY alike, then when I link together the following two
translation units:

	one.c:
	-------------------------------------------------------------------
	int xxyyz;
	int xxyyz;
	int xxyyz;
	-------------------------------------------------------------------
	two.c:
	-------------------------------------------------------------------
	int xxyyz;
	int xxyyz;
	int xxyyz;
	-------------------------------------------------------------------

I should get EXACTLY the same number and types of errors (no more and
no less) as I would get when I tried to like together the following two
translation units:

	three.c:
	-------------------------------------------------------------------
	int xxyyz = 0;
	-------------------------------------------------------------------
	four.c:
	-------------------------------------------------------------------
	int xxyyz = 0;
	-------------------------------------------------------------------

Now I'm willing to conceed that this may not have been what x3j11 intended,
however that *is* the way 3.7.2 reads.

You are suggesting that the true meaning of 3.7.2 is that if there is a
whole set of tenative definitions for some symbol within a given set of
linker input files, that the linker is supposed to create one (and only
one) zero initializer for the whole set.

I know that this is the way that things were traditionally done, but I
certainly *don't* yet know if that was the intent of x3j11.

I wish that somebody who was on x3j11 would tell me if that was the
committee's intent or not.

If it *was* the intent of x3j11 to do things in the traditional manner,
I think that they should have worded 3.7.2  so that that would have been
more clear.

-- 

// Ron Guilmette  -  C++ Entomologist
// Internet: rfg at ncd.com      uucp: ...uunet!lupine!rfg
// New motto:  If it ain't broke, try using a bigger hammer.



More information about the Comp.std.c mailing list