为什么 C 和 C++ 中有二合字母?

发布于 2024-07-12 03:05:32 字数 457 浏览 6 评论 0原文

今天我了解到 C99 中有 有向图 和C++。 以下是一个有效的程序:

%:include <stdio.h>

%:ifndef BUFSIZE
 %:define BUFSIZE  512
%:endif

void copy(char d<::>, const char s<::>, int len)
<%
    while (len-- >= 0)
    <%
        d<:len:> = s<:len:>;
    %>
%>

我的问题是:它们为什么存在?

I learned today that there are digraphs in C99 and C++. The following is a valid program:

%:include <stdio.h>

%:ifndef BUFSIZE
 %:define BUFSIZE  512
%:endif

void copy(char d<::>, const char s<::>, int len)
<%
    while (len-- >= 0)
    <%
        d<:len:> = s<:len:>;
    %>
%>

My question is: why do they exist?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

美人迟暮 2024-07-19 03:05:32

二合字母是为没有支持 ISO 646 字符集的键盘的程序员创建的。

http://en.wikipedia.org/wiki/C_trigraph

Digraphs were created for programmers that didn't have a keyboard which supported the ISO 646 character set.

http://en.wikipedia.org/wiki/C_trigraph

花开柳相依 2024-07-19 03:05:32

我相信它们的存在可以追溯到可能性,在某个地方,有人正在使用一个操作系统的编译器,该操作系统的字符集非常古老,以至于它不一定具有 C 或 C 语言中的所有字符。 C++需要表达整个语言。

此外,它还可以在 IOCCC 中提供良好的条目。

I believe that their existence can be traced back to the possibility that somewhere, somebody is using a compiler with an operating system whose character set is so archaic that it doesn't necessarily have all the characters that C or C++ need to express the whole language.

Also, it makes for good entries in the IOCCC.

不语却知心 2024-07-19 03:05:32

我认为这是因为这个星球上的某些键盘可能没有像“#”和“{”这样的键。

I think it's because some of the keyboards on this planet might not have keys like '#' and '{'.

要走就滚别墨迹 2024-07-19 03:05:32

C/C++ 中的二合字母和三合字母来自 CDC6000(60 位)、Univac 1108(36 位)、DECsystem 10 和 20 系统(36 位)使用的六位字符集时代,每个系统都使用专有的 64 个字符设置与 ASA X3.4-1963(现在称为 ANSI X3.4-1963“7 位美国国家信息交换标准代码”)不兼容。 最新修订版是 ANSI X3.4-1986。

由于这些系统无法表示所有 96 个图形代码点,因此省略了许多系统。 此外,X3.4 与其他国家标准机构(GBR、GER、ITA 等)协调,X3.4 中的代码点被指定为国家替换字符 - 最明显的例子是英镑的 #符号(很明显,因为 # 字符的名称是“英镑符号”,这是美国商业中的常规用法 - 在 Twitter 发展之前)和“{”“}”也被指定为国家替换字符。

因此,引入二合字母是为了为那些无法表示字符的计算机系统以及为冲突代码点分配国家替换字符的数据终端设备提供一种机制。 Di/Tri-graphs 已经成为计算历史上的一个古老的产物(现在计算机科学中不教授这个科目)。

关于此主题的详尽论文可以在这里找到:http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.96.678&rep=rep1&type=pdf

The digraphs and trigraphs in C/C++ come from the days of six bit character sets used by the CDC6000 (60 bits), Univac 1108 (36 bits), DECsystem 10 and 20 systems (36 bits) each of which used a proprietary 64 character set not compatible with the ASA X3.4-1963 (Now know as ANSI X3.4-1963 "7-bit American National Standard Code for Information Interchange"). The latest revision is ANSI X3.4-1986.

Since these systems were incapable of representing all of the 96 graphical code points, many were omitted. In addition, X3.4 was coordinated with other National Standard Institutes (GBR, GER, ITA, etc) and there were code points in X3.4 which were designated as national replacement characters - the most obvious example is the # for the Britsh Pound symbol (obvious because the name of the # character is "pound sign" from it's conventional usage in US commerce - prior to the the evolution of Twitter) and the '{' '}' were also designated as national replacement characters.

Thus digraphs were introduced to provide a mechanism for those computer systems incapable of representing the characters, and also for data terminal equipment which assigned national replacement characters to the conflicting code points. Di/Tri-graphs have become a archaic artifact of computing history (a subject not taught in computer science these days).

An exhaustive paper on this subject can be found here: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.96.678&rep=rep1&type=pdf

你的心境我的脸 2024-07-19 03:05:32

根据维基百科上的文章,它们被创建为三字母组合的更简单替代方案。

即,对于 5 个三字母 ??(, ??), ??<, ??> , ??=,提供了替换二合字母:<::><%%>%:。 这件事发生在1994年。

They were created as a simpler alternative to trigraphs according to the article on Wikipedia.

I.e., for 5 trigraphs ??(, ??), ??<, ??>, ??=, the replacing digraphs were supplied: <:, :>, <%, %>, %:. This happened in 1994.

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