H Bellamy H Bellamy - 10 months ago 42
C++ Question

Why would the character 'A' be compared with 0x41?

I was looking at some C++ code and found the following construct:

if('A' == 0x41) {
// ...
} else if('A' == 0xc1) {
// ...
} else {
// ...

I get a Visual Studio warning saying:

Warning C4127 conditional expression is constant.

Visual Studio is clearly right - surely 'A' is defined to be 0x41. Why is the author writing this code, given that two out of the three branches are dead code?

Answer Source

0xc1 is the EBCDIC character set code for 'A'. The author is testing for such a machine.