4.2 extern a DISASTER (Flame)

Doug Boyce boyce at daemen.UUCP
Wed Jul 31 08:31:33 AEST 1985


> 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



More information about the Comp.lang.c mailing list