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自我感觉,方法二,比较好
相关文章推荐
- warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
- warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
- 编译提示: warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
- warning C4800: 'VARIANT_BOOL' : forcing value to bool 'true' or 'false' (performance warning)
- AndroidManifest.xml警告 Should explicitly set android:allowBackup to true or false Android
- warning C4800: “BOOL”: 将值强制为布尔值“true”或“false”(性能警告)
- C++中用Int转成bool时,只有0是false,其他都是true。这个和其他语言很不一样,注意不要掉坑里了。
- Mysql:You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true
- warning C4800: “int”: 将值强制为布尔值“true”或“false”(性能警告)
- java.lang.RuntimeException: Value <pre>bool(false) of type java.lang.String cannot be converted to J
- warning C4800: “BOOL”: 将值强制为布尔值“true”或“false”(性能警告)
- [android警告] AndroidManifest.xml警告 Should explicitly set android:allowBackup to true or false
- [android警告] AndroidManifest.xml警告 Should explicitly set android:allowBackup to true or false
- warning C4800: “BOOL”: 将值强制为布尔值“true”或“false”(性能警告)
- C# transfer value from string to int
- C# bool true, false 操作符重载,用在 if, while等语句中
- Err:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array
- long[] or int[] convert to string[] method
- incompatible integer to pointer conversion assigning to 'BOOL * _Nonnull' (aka 'bool *')from 'int'
- [NSNull intValue]: unrecognized selector sent to instance 0x375c9860