Skip to main content
GameDev.net gamedev.net
🔒 Locked

Warnings

Started by utilae Oct 14, 2005 at 10:49 PM 7 replies 2.5k views
Original Post
utilae
utilae
Hi, I am using C++ and Visual Studio .NET 2003. My program compiles with alot of warnings, like below. Is it possible for warnings like this, especially the ones that say " 'signed char' : forcing value to bool 'true' or 'false' (performance warning)" to cause memory errors, eg memory leaks or memory corruption. Vertex.cpp Vertex.cpp(29) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Vertex.cpp(54) : warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data Vertex.cpp(54) : warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data Vertex.cpp(55) : warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data Vertex.cpp(55) : warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data Vertex.cpp(56) : warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data Vertex.cpp(56) : warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data Vertex.cpp(57) : warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data Vertex.cpp(57) : warning C4244: '=' : conversion from 'LONG' to 'float', possible loss of data Texture.cpp Texture.cpp(259) : warning C4244: '=' : conversion from 'double' to 'LONG', possible loss of data Texture.cpp(1910) : warning C4244: 'initializing' : conversion from 'float' to 'long', possible loss of data Texture.cpp(1911) : warning C4244: 'initializing' : conversion from 'float' to 'long', possible loss of data Texture.cpp(1912) : warning C4244: 'initializing' : conversion from 'float' to 'long', possible loss of data Texture.cpp(1913) : warning C4244: 'initializing' : conversion from 'float' to 'long', possible loss of data SubGlobals.cpp Sound.cpp Sound.cpp(179) : warning C4244: 'argument' : conversion from 'const float' to 'int', possible loss of data Sound.cpp(186) : warning C4244: 'initializing' : conversion from 'const float' to 'int', possible loss of data Sound.cpp(345) : warning C4800: 'signed char' : forcing value to bool 'true' or 'false' (performance warning) Sound.cpp(481) : warning C4244: 'initializing' : conversion from 'const float' to 'int', possible loss of data Sound.cpp(482) : warning C4800: 'signed char' : forcing value to bool 'true' or 'false' (performance warning) Sound.cpp(488) : warning C4800: 'signed char' : forcing value to bool 'true' or 'false' (performance warning) RtsMain.cpp RtsMain.cpp(372) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data RtsMain.cpp(373) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data mmgr.cpp Interface.cpp Interface.cpp(243) : warning C4018: '<' : signed/unsigned mismatch Interface.cpp(311) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Interface.cpp(334) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Interface.cpp(357) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Interface.cpp(370) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data Interface.cpp(372) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data Interface.cpp(403) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(404) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(421) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Interface.cpp(444) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Interface.cpp(467) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Interface.cpp(480) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data Interface.cpp(482) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data Interface.cpp(513) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(514) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(747) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(748) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(775) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(776) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(1113) : warning C4244: '=' : conversion from 'double' to 'long', possible loss of data Interface.cpp(1115) : warning C4244: '=' : conversion from 'double' to 'long', possible loss of data Interface.cpp(1130) : warning C4244: '=' : conversion from 'double' to 'long', possible loss of data Interface.cpp(1132) : warning C4244: '=' : conversion from 'double' to 'long', possible loss of data Interface.cpp(1146) : warning C4244: '=' : conversion from 'double' to 'long', possible loss of data Interface.cpp(1148) : warning C4244: '=' : conversion from 'double' to 'long', possible loss of data Interface.cpp(1155) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data Interface.cpp(1266) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(1269) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(1272) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(1273) : warning C4244: '=' : conversion from 'float' to 'LONG', possible loss of data Interface.cpp(1804) : warning C4244: 'argument' : conversion from 'double' to 'const float', possible loss of data Interface.cpp(2029) : warning C4244: 'argument' : conversion from 'double' to 'const float', possible loss of data Interface.cpp(2043) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Interface.cpp(2256) : warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation Globals.cpp D3D9Engine.cpp D3D9Engine.cpp(110) : warning C4244: 'argument' : conversion from 'const int' to 'FLOAT', possible loss of data D3D9Engine.cpp(110) : warning C4244: 'argument' : conversion from 'const int' to 'FLOAT', possible loss of data D3D9Engine.cpp(132) : warning C4805: '!=' : unsafe mix of type 'DWORD' and type 'bool' in operation
HTML5, iOS and Android Game Development using Corona SDK and moai SDK
stylin
stylin
There's no memory corruption in those conversion in and of themselves. However, if you're using a float to describe the length of some incredibly large array (for some odd reason) you could end up with logic errors. Similarly, converting any integral to a bool is just unwise (if the value of a positive int would have a true meaning conceptually, then a conversion to bool makes sense).

The thing you have to look out for is truncation. A good remedy for this is to refactor to utilize consistent, compatible and relavent types for your data.
:stylin: "Make games, not war." "...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
Conner McCloud
Conner McCloud
Quote:
Original post by utilae
Hi, I am using C++ and Visual Studio .NET 2003. My program compiles with alot of warnings, like below. Is it possible for warnings like this, especially the ones that say " 'signed char' : forcing value to bool 'true' or 'false' (performance warning)" to cause memory errors, eg memory leaks or memory corruption.

They should not cause memory leaks, but they can cause other issues. For instance, I notices a few double->long conversions. You lose a lot of information doing this, and if it isn't intentional this can lead to annoying little bugs.

The BOOL/DWORD/whatever->bool warnings can be even more annoying. Consider that for integers, 0 is false and everything else is true. This means that:

2 == true //falsebool(2) == true //true2 != false //truebool(2) != false //true


In short, don't ignore them, even though you're probably tempted to do so. Making them go away is pretty easy, and it forces you to consider whether or not you really want the behavior you're asking for.

CM
utilae
utilae
Quote:
Original post by Conner McCloud
They should not cause memory leaks, but they can cause other issues. For instance, I notices a few double->long conversions. You lose a lot of information doing this, and if it isn't intentional this can lead to annoying little bugs.

In cases like double to long or double to int, I am converting 4.5 to 4 or some such thing. In these cases I am always careful.

Quote:
Original post by Conner McCloud
The BOOL/DWORD/whatever->bool warnings can be even more annoying.

Here is one such use of DWORD and BOOL comparison that I am doing that results in the BOOL/DWORD warning:

DWORD  dwValue;//determine if renderstate is set to true or falseg_pD3DDevice9->GetRenderState(D3DRS_ALPHABLENDENABLE,&dwValue);//if the renderstate is falseif(dwValue!=true){        //set it to true	hr=g_pD3DDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE,true);	g_Log<<endl<<"SetupRenderStates() Alpha Blend Enable: "<<DXGetErrorString9(hr)<<endl;}
HTML5, iOS and Android Game Development using Corona SDK and moai SDK
stylin
stylin
What compels you to use a DWORD? Does it simply mean true or false, or does it store more information?
:stylin: "Make games, not war." "...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
Conner McCloud
Conner McCloud
Quote:
Original post by utilae
In cases like double to long or double to int, I am converting 4.5 to 4 or some such thing. In these cases I am always careful.

If you are aware of the conversion, and of the consequences of making it, then provide an explicit cast and the warning goes away.

CM
utilae
utilae
I have edited my code, forgot to include:
g_pD3DDevice9->GetRenderState(D3DRS_ALPHABLENDENABLE,&dwValue);

as you can see the dwValue contains either a true or false value and is used for testing the renderstate in direct3d9.
HTML5, iOS and Android Game Development using Corona SDK and moai SDK
stylin
stylin
Whenever you're using an API (or any interface) you should always follow the convention of the API. In this case, you should use TRUE, which is defined as an int (DWORD), instead of true. This will make that warning go away.
:stylin: "Make games, not war." "...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
iMalc
iMalc
Mostly when I see warnings about stuff like conversion from double to long it's because someone wrote something like:
foobor = (foo + bar) * 0.5;
You should try your best to avoid conversions between floating point and fixed point, because they are very slow anyway. Use code like this instead:
foobor = (foo + bar) / 2;
I would fix up all of those warnings if it were me. Post some code if you want help with that.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.