File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -17,13 +17,23 @@ integer values.
1717 uint8_t v = 65;
1818 std::cout << v; // output 'A' instead of '65'
1919
20- It could be fixed as
20+ The check will suggest casting the value to an appropriate type to indicate the
21+ intent, by default, it will cast to ``unsigned int `` for ``unsigned char `` and
22+ ``int `` for ``signed char ``.
2123
2224.. code-block :: c++
2325
24- std::cout << static_cast<uint32_t>(v);
26+ std::cout << static_cast<unsigned int>(v); // when v is unsigned char
27+ std::cout << static_cast<int>(v); // when v is signed char
2528
26- Or cast to char to explicitly indicate the intent
29+ To avoid lengthy cast statements, add prefix ``+ `` to the variable can also
30+ suppress warnings.
31+
32+ .. code-block :: c++
33+
34+ std::cout << +v;
35+
36+ Or cast to char to explicitly indicate that output should be a character.
2737
2838.. code-block :: c++
2939
You can’t perform that action at this time.
0 commit comments