Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!husc6!bunny!rhb6 From: rhb6@bunny.UUCP (Robert H. Barkan) Newsgroups: comp.sys.ibm.pc Subject: MSC multiple-definition bug or feature? Keywords: Strange MSC linker behavior Message-ID: <6215@bunny.UUCP> Date: 19 Oct 88 23:41:31 GMT Organization: GTE Laboratories, Waltham, MA Lines: 59 In MSC 5.x, compile the following 2 files, then link x1.obj and y1.obj. The linker should complain because "int x" is multiply defined: file x1.c: file y1.c: ========== ========== int x, eks = 'x'; int x, why = 'y'; main() y() { { x = eks; x = why; printf("File X1, x: %c\n", x); printf("File Y1, x: %c\n", x); y(); } printf("File X1, x: %c\n", x); } So far, so good. Now change x to something other than an integer, recompile, and try to link together x2.obj and y2.obj: file x2.c: file y2.c: ========== ========== int *x, eks = 'x'; int *x, why = 'y'; main() y() { { x = &eks; x = &why; printf("File X2, *x: %c\n", *x); printf("File Y2, *x: %c\n", *x); y(); } printf("File X2, *x: %c\n", *x); } Surprise, it's no longer an error! The linker is happy now, and produces x.exe. And of course running x.exe gives the (un)expected side effect: File X2, *x: x File Y2, *x: y File X2, *x: y Now, just for fun, try linking x2.obj with y1.obj. Now we have x defined as (int *) in x2, and x defined as (int) in y1. The linker is still happy, and the side effect is even better: File X2, *x: x File Y1, x: y File X2, *x: [ some smiley faces, musical notes, & other ascii "noise" ] Finally, I took this code over to a Sun3/OS3.5, and it didn't complain about any of the versions! Of course, you normally wouldn't code like this (these examples were simplified from a bug we found in a larger program). But what is unique to the MS linker about multiple definitions of int, but not other types? Bob Barkan rhb6%bunny@harvard.harvard.edu GTE Labs rhb6@gte.com 40 Sylvan Road Waltham, MA 02254 -- Bob Barkan GTE Laboratories 40 Sylvan Rd rhb6%bunny@harvard.harvard.edu Waltham, MA 02254 rhb6%gte.com@relay.cs.net (617) 466-2568