Date: Tue, 5 Sep 1995 17:22:46 -0700 (PDT) From: Archie Cobbs <archie@tribe.com> To: questions@freebsd.org Cc: archie@tribe.com Subject: multiple variable definitions in object files Message-ID: <199509060022.RAA10570@bubba.tribe.com>
next in thread | raw e-mail | index | archive | help
Hello,
Can someone explain why the linker allows multiple definitions of
a variable to be linked together without complaining or warning?
I found this surprising... I thought this was a no-no. At least it
has always caused errors in the past it seems.
I didn't see any relevant info in the ld(1) man page.
For example:
======== foo.c ============
int global;
main()
{
global = 2;
printf("foo: global = %d\n", global);
bar();
}
======== bar.c ============
float global;
bar()
{
printf("bar: global = %f\n", global);
}
======== compile with ==========
$ cc -o foobar foo.c bar.c
$ foobar
foo: global = 2
bar: global = 0.000000
$
Thanks for any insight,
-Archie
_______________________________________________________________________________
Archie L. Cobbs, archie@tribe.com * Tribe Computer Works http://www.tribe.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199509060022.RAA10570>
