Mail Archives: djgpp/1996/09/16/08:44:13
From: Thomas Nilsson <thoni AT softlab DOT se>
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
- Raw text -