c++asciipngebcdic

C/C++ character literals on ASCII and EBCDIC systems


After reading the PNG specification I was a little bit surprised. I've read character literals should be hardcoded with binary values like 0x41 not in (the programmer friendly) 'A'. The problem seems to be that character literals are differently encoded during compilation on different systems with different underlying character sets.

Okay well I asked friends and read the C++ Standard (ISO/IEC 14882:1998/e) but I didn't get/found the answer if the conversation depends on the system that I use to compile or it's a fixed character set (like ASCII) ever?


Solution

  • The programmer friendly version is the only way to be sure that the character constant 'A' is properly encoded for the target environment. Using 0x41 guarantees that the value is 65 only.

    EBCDIC systems are thankfully rare, and getting rarer, so this distinction is fairly academic in some ways. However, understandable programs are written meaningfully and as naturally as possible. Not abstractly.