warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)

The Visual Studio compiler makes a big deal of int to bool conversions.
For example, if you do:

	bool	bPunct = ispunct(c);	// causes warning

You'll get the warning.  So how about this attempt at a fix:

   :
        bool bPunct = (bool) ispunct(c); // still causes warningNo luck. The help file says its "by design" 
                                  //for a cast not to hide thewarning. Here are a number of ways to get around 
                                  //the warning.Use a macro to do the conversion:

   :
        #define MKBOOL(_a) ((_a) != 0)

        bool bPunct = MKBOOL(ispunct(c)); // No warningUse BOOL (which is an int in Windows):

   : 
        BOOL bPunct = ispunct(c); // No warningDisable the warning (perhaps in your stdafx.h file):
   :
        #pragma warning(disable: 4800) // disables the warning 

자기 느낌
다음으로 전송:http://www.davekb.com/browse_programming_tips:warning_C4800_int_forcing_value_to_bool_true_or_false_performance_warning:txt

좋은 웹페이지 즐겨찾기