Uninitialized C++ structure on different operating systems
We have application which is written in VC++ using Visual studio 2005, that supports multiple opertaing systems like Windows XP, Windows 2008, Windows 2003. Most of the time the Server part o开发者_开发百科f the application gets installed on Windows 2003 / Windows 2008 and Client part gets installed on Windows XP. Client and Server communicate through named pipes.
On client side we have created C++ structure and post it to server as IPC message. When we declare structre in function and don't initialize it, it reaches to server from some clients while it won't happen from some other clients. Clients are installed on different Windows XP machines.
Now, if I call ZeroMemory()
function on that structure and initialize it to zero, IPC message reaches to server from all the clients.
My question is, why unitialzied structre works on some machine and don't work on others? I have lot of curiosity on how uninitialized structures gets initialzed automatically by operating systems.
Uninitialized structures do not get initialized by the OS. Their members have whatever values happen to be in the memory at this time.
Trying to do something with uninitialized memory can lead to unpredictable results.
精彩评论