delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/28/17:50:30

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: djgpp bug
Date: Wed, 28 May 1997 12:46:02 -0700
Organization: Alcyone Systems
Message-ID: <338C8B7A.4B4EB4C@alcyone.com>
References: <Pine DOT SUN DOT 3 DOT 96 DOT 970528105752 DOT 17268A-100000 AT dia DOT csd DOT uch DOT gr>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
Lines: 30
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


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