🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #808

question about linkage

#808
From: Matthew Self
Date: Sat, 21 Oct 1989 18:31
46 lines
1838 bytes
Is K&R2 correct in saying (p. 227):

    If the first external declaration for a function
    or object includes the static specifier, the
    identifier has internal linkage; otherwise it has
    external linkage.

If so, then the identifier foo has external linkage in the
following program:

extern int foo[];

/* lots of references to foo here. */

static int foo[] = {0, 1, 2, 3};

How, then, can you forward declare an object with internal
linkage whose size isn't known when you forward declare it?
The logical thing to use appears to be:

static int foo[];

/* lots of references to foo here. */

static int foo[] = {0, 1, 2, 3};

Since the first declaration will be taken to be a tentative
definition of foo, which will later be demoted to a declaration
when the second definition is seen.

Unfortunately, every compiler I have tried complains that foo has
unknown size when you try this.

Also worth mentioning is the fact that traditional compilers seem
to give foo internal linkage rather than external in the first
example, indicating that this was how they solved the problem before
ANSI came along.  ANSI seems to have perverted the traditional
method for doing this without providing an alternative.

It is not possible to simply reorder the code to avoid the forward
reference, since this code is generated by a translator, and this
would require huge amounts of buffering!

Matthew Self
mself@next.com
Technical Details
Message-ID: <80@bomb.next.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!uakari.primate.wisc.edu!ames!sun-barr!newstop!sun!coherent!next!mself

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!uakari.primate.wisc.edu!ames!sun-barr!newstop!sun!coherent!next!mself
From: mself@next.com (Matthew Self)
Newsgroups: comp.std.c
Subject: question about linkage
Message-ID: <80@bomb.next.com>
Date: 21 Oct 89 18:31:48 GMT
Reply-To: mself@bomb.UUCP (My Account)
Organization: NeXT, Inc.
Lines: 46