• Advertisement

Archived

This topic is now archived and is closed to further replies.

Turning off warnings?

This topic is 6000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Ask yourself if you really want the compiler to not warn you about stuff, especially performance warnings.

Share this post


Link to post
Share on other sites
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...


Share this post


Link to post
Share on other sites
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 .

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement