Date: Mon, 16 Sep 1996 15:26:53 -0300 Message-Id: <1.5.4.16.19960916122832.29a7d2c4@dmeasc.rc.ipt.br> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: kagel AT dg1 DOT bloomberg DOT com, thoni AT softlab DOT se From: Cesar Scarpini Rabak Subject: Re: Possible static data zeroisation bug in DJGPP v2? Cc: djgpp AT delorie DOT com At 08:30 16/09/96 -0400, kagel AT quasar DOT bloomberg DOT com wrote: > From: Thomas Nilsson > Date: Fri, 13 Sep 1996 19:23:43 +0200 > > I have an application which I mainly develop on Unix, however thanks to > the wonderful DJGPP it's very easy to port to PC's, thanks all who have > contributed in the DJGPP project!! >[SNIP] > The structure is declared static at the top level of the module and in > the beginning of the file, but still gdb says 'No symbol xxxx in current > context'. The structure *should* not be used before that point in the > running of the program, but it is not zero as I would have expected. > >Static and global variables are not initialized or zero'd unless explicitly >initialized in the code. You have just been lucky because UNIX zeros the Excerpt from K&R Book 2nd ed. pg 40: "...External and static variables are initialized to zero by default." I have no ANSI/ISO standard handy by now, but it is on the standard as well (I think on section four). >memory pages it assigns to a process so the garbage you have been getting just >happened to be the zeros you wanted. DOS does not zero memory nor does the >DPMI spec require this (IMHO) so DJGPP does not zero uninitialized memory. > > This being strange, but still I wanted to investigate this structure, so > I removed the static declaration to make it more visible, and thought > that I might get at it already at the start of the program. And of > course I could, *but* now it is zeroised correctly and not destroyed so > the program works perfectly... > >Just lucky that globals are probably allocated before statics so now your >structure is on a different memory page with different garbage. > >You really should convert the definition of the structure to an initialized >definition. Never rely on the value of a variable you have not explicitly >set. > > Is this a bug, or if not, how do I find out when the structure is > trashed. Note however that Purify (a lovely memory access analyser for > many plattforms) does not indicate any problems on Unix (so at least > it's not a general bug, but then which ones are...) > >Purify reports no problem because none exists you are just suffering from GIGO. > > ------------------------------------------------------------------------ > >-- >Art S. Kagel, kagel AT quasar DOT bloomberg DOT com > >A proverb is no proverb to you 'till life has illustrated it. -- John Keats > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cesar Scarpini Rabak E-mail: csrabak AT ipt DOT br DME/ASC Phone: 55-11-268-35221Ext.350 IPT - Instituto de Pesquisas Tecnologicas Fax: 55-11-268-5996 Av. Prof. Almeida Prado, 532. Sao Paulo - SP 05508-901 BRAZIL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~