Click to See Complete Forum and Search --> : Application developed under C++6.0 NT crash under W95and98 (initialization of variable)


April 28th, 1999, 10:55 AM
My team develop a software with visualC++6.0 under NT. Testing of the application under NT is good. But, with Windows95 and 98, our application crash in several points. We've found that variables not initialize in the code yield a error. This missing initialization seems to be relevant for Windows95 or 98 but do not yields any bugs under NT. Do you know if visual offers a option or a setting for this type of bug. Because we have to fixe it variable per variable in the sources of several developer teams.... Thank you

April 28th, 1999, 11:14 AM
>We've found that variables not initialize in the code yield a error.

Let me get this straight. You are using uninitialized variables and you are SUPRISED that the code does not work properly?!?!? I hope to god that non of them are pointers! You ALWAYS initialize variables before use!

>Do you know if visual offers a option or a setting for this type of bug.

BUG??? It amazes me when people fail to follow proper programming practices and then blame the results on a "bug".

Fix your code to initialize all variables and especially all pointers (also a good idea to declare pointers like "CMyClass * foo = NULL;" and then test for NULL in ASSERTS where you use them.%3

Paul McKenzie
April 28th, 1999, 12:48 PM
You are supposed to initialize all variables. It has *nothing* to do with running Win 95/98, NT, UNIX, OS/2, Beos, Linux, whatever.

Uninitialized variables are the major cause of software written in C or C++ working great on one machine, and failing on another.

Regards,

Paul McKenzie

Roger Osborn
April 28th, 1999, 03:34 PM
The only real fix is to pay out for a good tool like Purify or Boundschecker to check for erroneous use of variables/heap and then have a test plan that ensures full coverage of your program paths. Both tools have their strengths but personally I prefer Purify because you don't have to rebuild the app to use it. Good coding practice will get you so far, but something always sneaks through.
NT clears memory in some situations where 95 doesn't, and zero is often the value you meant to assign anyway so you think you got it right until you try 95. In Release mode the compiler will sometimes warn about "used before initialized variables"; treat it as an error, not a warning.