Turning off warnings?

Started by
8 comments, last by MadProgrammer 22 years, 7 months ago
how do i go about turning off certain warnings? especially: c:\file.cpp(438) : warning C4800: ''int'' : forcing value to bool ''true'' or ''false'' (performance warning) I WANT THAT TO GO AWAY!!! i think there is a way using the #pragma, but i not shure how ne help would be good
Advertisement
Ask yourself if you really want the compiler to not warn you about stuff, especially performance warnings.
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
I just wonder whether some people ever check their online documentation. The answer lies in MSDN (hint: search for pragma).

Okay, I''ll tell you.
  // save warning state#pragma warning( push )// disable warnings warn_num1, warn_num2, warn_num3, etc#pragma warning( disable : warn_num1 warn_num2 warn_num3 ... )// restore warning states#pragma warning( pop )// get on with life...  

The easiest way is to figure out why it is generating a warning and fix it in you code. A warning is like a yellow traffic light, your supposed to slow down not speed up to get through .
Yup, the only warnings I disable are those generated by MSVC because STL symbol names are too long.

To fix your warning, you want to do this:
int bar;
bool foo = bar; // what you have
bool foo = bar != 0; // probably what you want
if you have
int x;
bool b;

is it really faster to do
b = x != 0;
than it is to do
b = x;

????
i think i would prefer to turn off that warning. i agree that warnings bout non-used vars and stuff like that shouldn''t be turned off, but sometimes u just get annoney by stuff
After a couple of hours of meetings at work on this subject, my coworkers and I have decided that the reason for this warning is that if you''re doing this kind of assignment, that "int" should really be a "bool" in the first place, and that''s what the compiler''s trying to tell you.
I''ve had the int/bool warning before. I usually just fix it a cast, if its not a real error. And sometimes it is an error - thats why i don''t turn it off.

Like stoffel, the only warning i turn off is the warning about long internal template names generated by MSVC. Sometimes I''m really tempted to turn off the double/float warning - there are so many MSVC mathematical functions that return a double when all i need is a float.
Debug this, and look at the disassembly... You''ll note that it takes 1 additional instructions to convert the int to a bool....

These result in IDENTICAL assembly..

int i = 10;
bool b = i;

int i = 10;
bool b = i != 0;

The most efficient way is :

int i = 10;
bool b = i == 0 ? false : true;

This results in 3 instructions( instead of four ).

Additionally, you could use a BOOL, instead of a bool, and not get the warning at all...

Leave the warnings on, they have their purpose.

Anyway, I''m sure this is moot at this point...

Zerapolis


"It''s only after you''ve lost everything that you''re free to do anything." Tyler Durden
"It's only after you've lost everything that you're free to do anything." Tyler Durden
quote:Original post by Stoffel
After a couple of hours of meetings at work on this subject, my coworkers and I have decided that the reason for this warning is that if you''re doing this kind of assignment, that "int" should really be a "bool" in the first place, and that''s what the compiler''s trying to tell you.

Yeah, but 99% of the time when this warning comes up, it''s because you''re trying to wrap one of the old C standard library functions in your own function that returns a bool. Eg.: using strcmp in an == operator. I think it''s a bit of a dubious warning, and on Visual C++ 6 I think it is at level 3... I think it should really be at level 4.

This topic is closed to new replies.

Advertisement