🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: "extern" and function declarations

#2198
From: Miguel Carrasquer Vidal
Date: Thu, 07 Mar 1996 00:29
66 lines
2799 bytes
fred@genesis.demon.co.uk (Lawrence Kirby) wrote:

>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)?

Worth the bandwidth: I'd say I had heard/read most of it somewhere
already (even though I don't read comp.std.c), but not quite all of it
(or else I had forgotten), so I certainly learnt something.  And it
could hardly have been explained any clearer.  

I was particularly impressed by the following:

>    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). 


It made me feel sorry for the poor compiler.  If I think about all the
times I've carelessly written stuff like "int i;" [well, not quite
that variable name of course] at the top of a source file, completely
unaware of the fact that I was only making a 'tentative definition'
and that the compiler had to go through all the rest of the file
(hundreds and hundreds of lines of code) anxiously going through
header files, scanning function definitions, waiting for that one
simple initialization...

...
extern int i;
   ...scan..scan...
extern int i;
   ...tokenize..tokenize...
int i;
   ...analyze..analyze...
int i;
   ...parse..parse...
int i = 1;
***aaahhhh***

But obviously that last line never came...  I don't know if I will
ever be able to write "int i;" again, casually thinking "oh, the
compiler will initialize it to zero".  It's such a small effort to
write "int i=0;" instead!


==
Miguel Carrasquer Vidal                     ~ ~
Amsterdam                   _____________  ~ ~
mcv@pi.net                 |_____________|||

========================== Ce .sig n'est pas une .cig
Technical Details
Message-ID: <4hlake$4gk@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: mcv@pi.net (Miguel Carrasquer Vidal)
Newsgroups: comp.lang.c.moderated
Subject: Re: "extern" and function declarations
Date: 6 Mar 1996 18:29:02 -0600
Organization: Planet Internet
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4hlake$4gk@solutions.solon.com>
References: <4hdqjq$8pr@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Newsreader: Forte Free Agent 1.0.82