Mail Archives: djgpp/1997/05/28/07:40:36
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 -