delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/28/07:40:36

Organization:
Date: Wed, 28 May 1997 14:34:54 +0300 (EET DST)
From: KOMODakis Nikolaos <komod AT csd DOT uch DOT gr>
To: Robert Hoehne <Robert DOT Hoehne AT Mathematik DOT tu-chemnitz DOT de>
Cc: KOMODakis Nikolaos <komod AT csd DOT uch DOT gr>, djgpp AT delorie DOT com
Subject: Re: djgpp bug
In-Reply-To: <338C1105.6097C25A@Mathematik.tu-chemnitz.de>
Message-Id: <Pine.SUN.3.96.970528142355.20590A-100000@gavdos.csd.uch.gr>
Mime-Version: 1.0

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;
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.

... Nick ... 

On Wed, 28 May 1997, Robert Hoehne wrote:

> KOMODakis Nikolaos wrote:
> > 
> > If you declare the same global (not static) variable in two different C
> > files, the compiler doesn't tell you anything (not even a warning).
> > However, it allocates the same space for the two definitions.
> 
> When gcc compiles one source file, it does nothing now about anything
> in any other source file.
> But when you link (NOTE link and not compile) these two files
> to an executable, then you will get an error. 
> 
> 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                       *
> *****************************************************************
> 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019