Strange phenomina in VC Ver 6.0

Strange phenomina in VC Ver 6.0

Post by mark » Thu, 12 Jan 2006 15:36:07


I developed a regular mfc dll and load it from another mfc executable. I use
static values and I encounter a phenomena in which one of them changes its
value without any asignment in release version while in debug compilation
everything is ok.

Can anyone advise please?

Regards

Mark
 
 
 

Strange phenomina in VC Ver 6.0

Post by Scherbina » Thu, 12 Jan 2006 15:46:43

Do you create threads that access your variable ? Do you sync. access to it
?
BTW, if you're talking about initialization value of variable then situation
seems to be clear:

bool bValue;

will be initialized with zero in release (false), and with garbage in Debug
(true).

--
Vladimir

 
 
 

Strange phenomina in VC Ver 6.0

Post by Alexander » Fri, 13 Jan 2006 00:55:50

Static/global variables are implicitly zero-initialized.
 
 
 

Strange phenomina in VC Ver 6.0

Post by Scherbina » Fri, 13 Jan 2006 00:59:34

btw, this question has been "expanded" in more details in
microsoft.public.vc.mfc ng.
 
 
 

Strange phenomina in VC Ver 6.0

Post by Jochen Kal » Fri, 13 Jan 2006 01:02:43

Hi Alexander!

Because they are put into the NON-INITILIZED section of the PE

:- ))))))))

ROFL

--
Greetings
Jochen

My blog about Win32 and .NET
http://www.yqcomputer.com/
 
 
 

Strange phenomina in VC Ver 6.0

Post by mark » Fri, 13 Jan 2006 15:34:53

Thanks all
Simply initializing the varibales solved the problem

Marrk
 
 
 

Strange phenomina in VC Ver 6.0

Post by Norman Dia » Sat, 14 Jan 2006 09:54:38

I think more likely the REASON is because the standard (and K&R's definition
prior to the standard) said that static (including global) variables are
implicitly zero-initialized.

If Microsoft's chosen MECHANISM is to put them into the non-initialized
section of the PE, then feel free to ROFL about the mechanism. It's
misleading to call this the reason though ("Because ...").
 
 
 

Strange phenomina in VC Ver 6.0

Post by Skywin » Sat, 14 Jan 2006 22:49:07

In case anyone was wondering, it's called "non-initialized" because there
the data isn't loaded into memory by disk (and is instead simply left zeroed
out initially). It's an optimization so that if you are creating large zero
filled variables (i.e. a big global array) then you don't significantly
increase the size of your final binary image on disk.
 
 
 

Strange phenomina in VC Ver 6.0

Post by Jochen Kal » Sat, 14 Jan 2006 22:58:16

Hi Skywing!


Yes.. I know about this....
I just ROFL about the naming from MS... better would been
"zero-initialized" instead of "non-initialized"....

Some people have some confusion about the "non"... because it is also
not stated explicit in the PE-docu that this data *must be* initialized
by zero!

--
Greetings
Jochen

My blog about Win32 and .NET
http://www.yqcomputer.com/