Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Variable not defined - really annoying error

Author
Message
Dark Lord
19
Years of Service
User Offline
Joined: 19th Aug 2005
Location: Australia
Posted: 12th Dec 2005 07:42
When I compile this code in Visual C++ 2003 I get the error message: "Run-Time Check Failure #3 - The variable 'fX' is being used without being defined."

The code is an example which I got from codebase for DBPro.

Could someone please tell me how to fix this?

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 12th Dec 2005 10:26
Dont you mean :

warning C4700: local variable 'fX' used without having been initialized

In C you can use a variable without defining it first.

This warning message means you are declaring it, and using it, but not initialising it first - thus the starting value will be undefined.

Kaiyodo
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: UK
Posted: 12th Dec 2005 12:31
Like I am my greatest fan says, the line "movelight(fY,fZ,fX,o);" uses the uninitialised variables fX,fY and fZ. Setting those to 0 at the start of the function will fix that.

I'm guessing that the person who posted the code in the codebase was compiling with VC6 as that version of the compiler doesn't add runtime checks for uninitialised variables that 2003 does. In DEBUG mode the variables would have been initialised to 0xCDCDCDCD, in release mode they would have been set to whatever was in the memory that the stack was pointing to at the time.

Kaiyodo.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 12th Dec 2005 17:06
Quote: "I'm guessing that the person who posted the code in the codebase was compiling with VC6 as that version of the compiler doesn't add runtime checks for uninitialised variables that 2003 does."


I dont know about runtime checks, but vc6 DEFINATLY informs you via the output console when you are using a variable without initialising it first.

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 12th Dec 2005 17:18
He did say VS 2003 - but I've never known it to come up with the error message given.

Kaiyodo
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: UK
Posted: 12th Dec 2005 21:47
I do have vague memories of VC6 warning you about uninitialised variables, but I wonder if that was with a higher warning level than the default. I remember being stung by it a few times in the past.

Kaiyodo.
Dark Lord
19
Years of Service
User Offline
Joined: 19th Aug 2005
Location: Australia
Posted: 13th Dec 2005 00:38 Edited at: 13th Dec 2005 01:09
Thank you, before this I was declaring all my variables as globals (my last C++ book told me that that was a bad practice - for debugging sake). However, if I declare the global float fArgA and 'forget' to initialise it then I get no error message, is that something to do with compiler or what?

btw the example which I converted was designed with DBPro

I also noticed that some of the commands in the example didn’t take the same parameters as the updated commands in the SDK - some didn’t even exist, in the example "set shadow shading on" took 4 arguments whereas "dbSetShadowShadingOn()" only takes 1, the DBP command "set shadow position" also appears to be excluded from the SDK. This could be an error in the code base post, or the SDK has slightly different commands.

[edit] Does the dbInKey() command even work?

Here is the new updated version in which everything works apart from the "if (dbInKey()=="")" statements:

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Dec 2005 01:21
Quote: "However, if I declare the global float fArgA and 'forget' to initialise it then I get no error message, is that something to do with compiler or what?"


No, perfectly acceptable to the compiler. Anything declared at global scope is automatically cleared to 0 when the program initialises, unless you have specified another value. It's only when you use local or heap-based values that it becomes a problem, as they are not cleared automatically.

Your dbInKey() commands need to do something like this:


I think that'll work, but you'll need to try it. I prefer to use the windows API for keyboard input.

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Dark Lord
19
Years of Service
User Offline
Joined: 19th Aug 2005
Location: Australia
Posted: 13th Dec 2005 02:18 Edited at: 13th Dec 2005 02:19
Thanks for the information about the compiler, I tried your strcmp() method and the program works now.

Here is the updated code:

Login to post a reply

Server time is: 2024-11-19 03:29:37
Your offset time is: 2024-11-19 03:29:37