C/C++ ASCII 和 EBCDIC 系统上的字符文字

发布于 2024-11-18 02:22:33 字数 212 浏览 8 评论 0原文

阅读 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不服输 2024-11-25 02:22:33

程序员友好的版本是确保字符常量 '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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文