4.2 extern a DISASTER (Flame)

M.J.Shannon mjs at eagle.UUCP
Tue Jul 16 00:01:16 AEST 1985


> 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 at 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



More information about the Comp.lang.c mailing list