Game Development Community

Refference to uninitlized variable" NOT a compiler error?

by Steven Peterson · in Technical Issues · 02/27/2006 (12:41 pm) · 9 replies

Just spent ALL day trying to track down a problem. Turns out I accidently commented out the 1 line where a pointer-variable was initlized before refferencing it later on.

Isn't this supposed to be a compiler warning or error? I know gcc used to pick up on these mistakes, but VC6 apparently doesn't. Is there somekind of flag or option I can set to get it to help me a little more?

No-wonder GG doesn't support VC6 anymore... But then it's such a piece of trash, i'm not in any rush to run out and buy the new version.

#1
02/27/2006 (12:47 pm)
Rofl.

vs6 should warn you of unreferenced variable.
but will not warn you otherwise no.

the ms crew sitting in the hottub smoking fatties thought it was a great idea.
but when the coders went to code it up.

they fell short and couldnt figure out how to detect if the pointer has been set or not.

so they axed it and said "we will add that to a service pack later"
#2
02/27/2006 (12:57 pm)
Thats amusing cuz an unrefferenced variable doesn't do quite as much damage as one thats refferenced but not inilized...

thx.
#3
03/09/2006 (1:27 pm)
Badguy:MS crew is not that bad. We are here as well(MS crew).
Faisal Shah
Microsoft Canada
#4
03/09/2006 (1:56 pm)
I thought VC6 warned of accessing unintialized variables..

.. yeah, it does:

void CBlorpDlg::OnOK() 
{
	int* pInt;

	if (pInt == NULL)
		; // do something
}

yields:
C:\tmp\progs\blorp\blorpDlg.cpp(176) : warning C4700: local variable 'pInt' used without having been initialized

so maybe something else is going on,
or your project is big and complicated enough to confuse VC6,
or you're using templates, or..
#5
03/11/2006 (8:55 am)
Uninitialised variable can be a lot of troubles. When you compile as Debug, all is nicely initialised to null (0) while this is not done in release. So a code that run fine in Debug my give you strange results in Release.

My experience with VC6, this may not apply to other compilers.
#6
03/12/2006 (3:13 pm)
It also depends on the "warning level" you set for the compiler. 4 is the highest (and will tell you things that generally don't cause problems, but certainly wouldn't hurt to fix), and 0 tells the compiler: "STFU".

I think uninited variables are picked up at warning level 3... which I find to be quite reasonable. YMMV.

--Mark
#7
03/13/2006 (9:20 am)
My test above was with a pretty fresh install of VC6, and a new project,
so whatever the default settings are which seem to be... Level 3.

Project | Settings | C/C++ | General | Warning Level
#8
03/13/2006 (9:30 am)
Greetings!

I just opened TGE 1.4 in VC6 and see that the Torque Demo project (both release and debug) are set to a warning level of 1. So with the above scale of 0=None, 4=Strict, you may want to up it for your own development.

I'm sure a setting of 1 made sense to someone at one point...

- LightWave Dave

PS: And loading TGE 1.4 under VS2005 I see that it is also set at a warning level of 1. Here's the list from MS:

Quote:/Wn
Specifies the highest level of warning generated by the compiler. Valid warning levels for n range from 0 to 4:

* Level 0 disables all warnings.

* Level 1 displays severe warnings. Level 1 is the default warning level at the command line.

* Level 2 displays all level 1 warnings and warnings less severe than level 1.

* Level 3 displays all level 2 warnings and all other warnings recommended for production purposes.

* Level 4 displays all level 3 warnings plus informational warnings, which in most cases can be safely ignored. This option should be used only to provide "lint" level warnings and is not recommended as your usual warning level setting.

For a new project, it may be best to use /W4 in all compilations. This will ensure the fewest possible hard-to-find code defects.
#9
03/27/2006 (10:33 am)
I'm revisitng old threads. Thanks for the great info guys, learn somthing new everyday! I'll deffinitly change those settings. :-)