Why is char distinct from signed char and unsigned char?

There are three distinct basic character types: char, signed char and unsigned char. Although there are three character types, there are only two representations: signed and unsigned. The (plain)char uses one of these representations. Which of the other two character representations is equivalent to char depends on the compiler. In an unsigned type, all the … Read more

Difference between char and signed char in c++?

There are three distinct basic character types: char, signed char and unsigned char. Although there are three character types, there are only two representations: signed and unsigned. The (plain)char uses one of these representations. Which of the other two character representations is equivalent to char depends on the compiler. In an unsigned type, all the … Read more

Is there some meaningful statistical data to justify keeping signed integer arithmetic overflow undefined?

I don’t know about studies and statistics, but yes, there are definitely optimizations taking this into account that compilers actually do. And yes, they are very important (tldr loop vectorization for example). Besides the compiler optimizations, there is another aspect to be taken into account. With UB you get C/C++ signed integers to behave arithmetically … Read more

Comparison operation on unsigned and signed integers

Binary operations between different integral types are performed within a “common” type defined by so called usual arithmetic conversions (see the language specification, 6.3.1.8). In your case the “common” type is unsigned int. This means that int operand (your b) will get converted to unsigned int before the comparison, as well as for the purpose … Read more