Skip to content

Commit e931492

Browse files
author
Colin Robertson
authored
Fix C4800 doc per Kate's question (#277)
1 parent e775744 commit e931492

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

docs/error-messages/compiler-warnings/compiler-warning-level-3-c4800.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,25 @@ translation.priority.ht:
3434
- "zh-cn"
3535
- "zh-tw"
3636
---
37-
# Compiler Warning (level 3) C4800
38-
'type' : forcing value to bool 'true' or 'false' (performance warning)
37+
# Compiler Warning (level 3) C4800
3938

40-
This warning is generated when a value that is not `bool` is assigned or coerced into type `bool`. Typically, this message is caused by assigning `int` variables to `bool` variables where the `int` variable contains only values **true** and **false**, and could be redeclared as type `bool`. If you cannot rewrite the expression to use type `bool`, then you can add "`!=0`" to the expression, which gives the expression type `bool`. Casting the expression to type `bool` will not disable the warning, which is by design.
39+
> '*type*' : forcing value to bool 'true' or 'false' (performance warning)
4140
42-
The following sample generates C4800:
41+
This warning is generated when a value that is not `bool` is assigned or coerced into type `bool`. Typically, this message is caused by assigning `int` variables to `bool` variables where the `int` variable contains only values **true** and **false**, and could be redeclared as type `bool`. If you cannot rewrite the expression to use type `bool`, then you can add "`!=0`" to the expression, which gives the expression type `bool`. Casting the expression to type `bool` does not disable the warning, which is by design.
4342

44-
```
43+
This warning is no longer generated in Visual Studio 2017.
44+
45+
## Example
46+
47+
The following sample generates C4800 and shows how to fix it:
48+
49+
```cpp
4550
// C4800.cpp
4651
// compile with: /W3
4752
int main() {
4853
int i = 0;
4954

50-
// try..
55+
// To fix, instead try:
5156
// bool i = 0;
5257

5358
bool j = i; // C4800

0 commit comments

Comments
 (0)