From owner-freebsd-questions Tue Sep 5 17:23:24 1995 Return-Path: questions-owner Received: (from majordom@localhost) by freefall.freebsd.org (8.6.11/8.6.6) id RAA12677 for questions-outgoing; Tue, 5 Sep 1995 17:23:24 -0700 Received: from bubba.tribe.com ([205.184.207.7]) by freefall.freebsd.org (8.6.11/8.6.6) with ESMTP id RAA12671 for ; Tue, 5 Sep 1995 17:23:22 -0700 Received: (from archie@localhost) by bubba.tribe.com (8.6.11/8.6.9) id RAA10570; Tue, 5 Sep 1995 17:22:47 -0700 From: Archie Cobbs Message-Id: <199509060022.RAA10570@bubba.tribe.com> Subject: multiple variable definitions in object files To: questions@freebsd.org Date: Tue, 5 Sep 1995 17:22:46 -0700 (PDT) Cc: archie@tribe.com X-Mailer: ELM [version 2.4 PL24] Content-Type: text Content-Length: 907 Sender: questions-owner@freebsd.org Precedence: bulk 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