From: kagel AT quasar DOT bloomberg DOT com Date: Mon, 16 Sep 1996 08:30:55 -0400 Message-Id: <9609161230.AA06984@quasar.bloomberg.com > To: thoni AT softlab DOT se Cc: djgpp AT delorie DOT com In-Reply-To: <3239989F.4626@softlab.se> (message from Thomas Nilsson on Fri, 13 Sep 1996 19:23:43 +0200) Subject: Re: Possible static data zeroisation bug in DJGPP v2? Reply-To: kagel AT dg1 DOT bloomberg DOT com 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 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