C/C++ ASCII 和 EBCDIC 系统上的字符文字
阅读 PNG 规范后,我有点惊讶。我读过字符文字应该使用二进制值进行硬编码,例如 0x41 而不是(程序员友好的)“A”。问题似乎在于,在具有不同底层字符集的不同系统上编译期间,字符文字的编码方式不同。
好吧,我问朋友并阅读了 C++ 标准(ISO/IEC 14882:1998/e),但如果对话取决于我用来编译的系统或者它是固定字符集(例如ASCII)曾经吗?
感谢您的回答。
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?
Thanks for your answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
程序员友好的版本是确保字符常量
'A'
针对目标环境正确编码的唯一方法。使用 0x41 可保证该值仅为 65。值得庆幸的是,EBCDIC 系统很少见,而且越来越少,因此这种区别在某些方面是相当学术性的。然而,可理解的程序是尽可能有意义且自然地编写的。不是抽象的。
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.