Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site daemen.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!rochester!rocksvax!sunybcs!daemen!boyce From: boyce@daemen.UUCP (Doug Boyce) Newsgroups: net.lang.c Subject: Re: Re: 4.2 extern a DISASTER (Flame) Message-ID: <776@daemen.UUCP> Date: Tue, 30-Jul-85 18:31:33 EDT Article-I.D.: daemen.776 Posted: Tue Jul 30 18:31:33 1985 Date-Received: Thu, 1-Aug-85 06:14:25 EDT References: <2643@hplabsc.UUCP> <1281@eagle.UUCP> <1282@eagle.UUCP> <2656@hplabsc.UUCP> Distribution: net Organization: Daemen College, Buffalo, NY Lines: 54 > This is where the problem is occuring: > > file1.c > > int foo; > > file2.c > > int uses_foo() > > { > extern int foo; > > ... > } > > According to the K&R standard, any references to foo within uses_foo() > should refer to the external variable in file1.c, and the linker > should take care of making the connection (unless, of course, there > is a static within file2.c's file scope which masks the external > definition). > > Not according to the 4.2 compiler, however. If I try to run this, > I get various bus errors, etc. (it links OK). > I tried that and didn't come across any problems. Script started on Tue Jul 30 18:26:02 1985 # cat a.c int foo; main() { usefoo(); foo = 3; printf("main: foo: %d\n",foo); } # cat b.c usefoo() { extern int foo; printf("usefoo: foo: %d\n",foo); } # cc a.c b.c a.c: b.c: # a.out usefoo: foo: 0 main: foo: 3 # script done on Tue Jul 30 18:26:49 1985