Mail Archives: djgpp/1997/05/28/17:50:30
KOMODakis Nikolaos wrote:
>
> I have accidentally found the following bug in djgpp:
> 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.
>
> I guess that this is a problem of the COFF format (that djgpp uses) and
> the way this format handles global variables.
This is not a DJGPP bug or COFF misfeature, this is an issue with
fundamentally the way C works. Each module is compiled atomically -- that
is, when compiling module A, the compiler has no knowledge of what it
might or might not have compiled in a previous module. (gcc should make
this clear because the program gets executed separate times in most
makefiles.)
Because of this lack of persistence, it has no way of knowing that the
external variable it found shouldn't have been defined twice. It should
give you an error when linking, though, so there's no problem.
This same kind of behavior would be found in _any_ C compiler.
--
Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
Alcyone Systems / web / http://www.alcyone.com/max/
San Jose, California, United States / icbm / 37 20 07 N 121 53 38 W
\
"Covenants without the sword / are but words."
/ Camden
- Raw text -