您的位置:首页 > 产品设计 > UI/UE

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

2013-09-11 14:49 1061 查看
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
自我感觉,方法二,比较好
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐