Date: Wed, 28 May 1997 14:20:56 +0200 (METDST) From: Robert Hoehne To: KOMODakis Nikolaos Cc: djgpp AT delorie DOT com Subject: Re: djgpp bug In-Reply-To: Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Wed, 28 May 1997, KOMODakis Nikolaos wrote: > > Perhaps, i did not made myself clear enough. > The two files (that contain the same global variable) are linked to an > executable and are not just compiled. > > For example: > > FILE 1 > ------ > int defined_twice; > int main(int argc, char **argv) { > defined_twice = 0; > dummy_call(); > printf("defined_twice is %d\n", defined_twice); > } > > FILE 2 > ------ > int define_twice; this should be int defined_twice; > void dummy_call() { > defined_twice = 1; > printf("defined_twice is %d\n", defined_twice); > } > > > If you compile and link these two files, you will get no error or warning > from djgpp. > Ok. You are right (I think, because I tested it not on DJGPP) but I tested it here on linux. But I think this is not a bug (or is it??). At least it is not DJGPP specific. And the next is. There is no space allocated for the variables when the file is compiled, but this is done by the linker because they go into the .bss section. And the linker then knows to not emit for the same common symbol the space twice. To get a warning about this, you have to add the '--warn-common' switch when linking like this: gcc -Xlinker --warn-common -o foo.exe file1.o file2.o And at last: If you change in both files (FILE 1 and FILE 2) the lines to lets say: int defined_twice = 0; then you will get an error when linking, because in this case the space for these variables are allocated already when compiling the file(s). Robert ***************************************************************** * Robert Hoehne, Fakultaet fuer Mathematik, TU-Chemnitz-Zwickau * * Post: Am Berg 3, D-09573 Dittmannsdorf * * e-Mail: Robert DOT Hoehne AT Mathematik DOT TU-Chemnitz DOT DE * * WWW: http://www.tu-chemnitz.de/~rho * *****************************************************************