🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2180

Re: "extern" and function declarations

#2180
From: Arun M. Thomas
Date: Tue, 05 Mar 1996 03:32
57 lines
3009 bytes
In article <4hdqjq$8pr@solutions.solon.com> fred@genesis.demon.co.uk 
					    (Lawrence Kirby) writes:
--SNIP--
:       int i;
:
:   This one is trickier than it first seems and you'll notice that I didn't
:   start with it. This is termed in the standard as a 'tentative definition'.
:   It can exist in a translation unit along with other declarations for
:   the identifier including a 'full' definition. So the following lines in a
:   single source file are legal:
:
:       extern int i;
:       extern int i;
:       int i;
:       int i;
:       int i = 1;
:
:   A 'tentative definition' becomes a definition if you get to the end
:   of the translation unit without encountering a 'full' definition
:   (i.e. with an initialisation). Tentative definitions are those
:   that you recognise as being implicitly initialised to zero (but
:   as you can see from the example that doesn't always happen).
:   int i; in a translation unit ensures that i will be defined by
:   that translation unit so you can't have int i in two translation units
:   because there would then be two definitions for the same object in the
:   program.
:
This is the first I've heard of tentative definitions (I'm fairly new at this).
Why are tentative definitions  recognised as being implicitly zero?  If the 
value of i in the above example is never initialized, (assuming the last line
was not present) then it should never be used anywhere.  In that case, why 
does one need to bother recognising this as zero?  

On a related note, does the concept of declaration vs definition apply to 
variables?  Or only to functions?  This "tentative definition" strikes me 
as somewhat similar.  

--SNIP--
:   I'm curious - do people find this enlightening (you learnt something),
:   obvious (you knew it already, comp.std.c regulars need not apply),
:   unintelligible (I didn't explain it very clearly) or uninteresting (not
:   worth the bandwidth)?
:
I, at least, found this useful :)  though I'm still not completely sure I 
understand.

:   I wonder how many C books or courses cover things like tentative
:   definitions (in whatever terminology). K&R2 discusses this in the language
:   reference in appendix A (A10.2) but not, as far as I can tell, in the
:   main tutorial.

I really don't recall ever having run into something like this in my C course
or in going through various books on C programming.  (I have K&R2, but have 
never gone through the appendix word for word.)

-Arun Thomas
Technical Details
Message-ID: <4hgcl2$9e8@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4hdqjq$8pr@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: thomas@eel.rdc.toshiba.co.jp (Arun M. Thomas)
Newsgroups: comp.lang.c.moderated
Subject: Re: "extern" and function declarations
Date: 4 Mar 1996 21:32:50 -0600
Organization: Toshiba Corporation, RDC Center, Kawasaki, JAPAN
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4hgcl2$9e8@solutions.solon.com>
References: <4hdqjq$8pr@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com