Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site eagle.UUCP Path: utzoo!watmath!clyde!burl!ulysses!eagle!mjs From: mjs@eagle.UUCP (M.J.Shannon) Newsgroups: net.lang.c Subject: Re: 4.2 extern a DISASTER (Flame) Message-ID: <1281@eagle.UUCP> Date: Mon, 15-Jul-85 10:01:16 EDT Article-I.D.: eagle.1281 Posted: Mon Jul 15 10:01:16 1985 Date-Received: Wed, 17-Jul-85 05:46:09 EDT References: <2643@hplabsc.UUCP> Distribution: net Organization: AT&T Bell Laboratories, Summit, NJ Lines: 37 > I find the 4.2 C compiler's treatment of extern a total and > complete DISASTER. I have so far been completely unsuccessful > at using extern.... > jim kempf kempf@hplabs From your note, it's unclear what you've done, but here's how the language defines what must happen: Correct: (file0.c) | (file1.c) extern int gronk; int gronk; Correct: int gronk; extern int gronk; Incorrect: /* linker should complain about gronk being undefined */ extern int gronk; extern int gronk; Incorrect: /* but most/many/some compilers accept this */ int gronk; int gronk; In all but the last case, the definition (declaration without extern) may include an initialization of gronk. The last case is somewhat special. The historical interpretation is that each file will result in a common area (of size (sizeof (int))) being defined for gronk, and the linker will resolve both names to the same address. Strictly speaking (according to K&R), if there are N files with declarations of gronk, N-1 of them must have extern. Most/many/ some compilers allow at most 1 initialization of gronk, and resolve all references to the initialized data. Does this answer your question? -- Marty Shannon UUCP: ihnp4!eagle!mjs Phone: +1 201 522 6063