For faster navigation, this Iframe is preloading the Wikiwand page for C替代标记.

C替代标记

C替代标记指一批C语言常见运算符的可选拼写。它们实现为C標準函式庫iso646.h头文件内的一组(台湾作巨集)定义。此标记作为C90标准的修正案于1995年增补。

替代标记允许程序员使用C语言按位和逻辑运算符,原先的标记在一些国际和非QWERTY键盘上很难输入。根据ISO/IEC 646标准实现的头文件有一些区域性的变化,其中一些用重音字符替换了C运算符使用的标点符号。

(台湾作巨集)定义

[编辑]

iso646.h中定义了11个(台湾作巨集):

(台湾作巨集 定义为
and &&
and_eq &=
bitand &
bitor |
compl ~
not !
not_eq !=
or ||
or_eq |=
xor ^
xor_eq ^=

C++

[编辑]

以上标识符全部是运算符关键字,因此不需要再包含头文件。为了兼容C语言,C++98标准提供了头文件<ciso646>,但实际上这是个空文件[1]。然而在Microsoft Visual C++等编译器中,如果使用这些运算符关键字,就必须包含头文件。

头文件名称来源

[编辑]

iso646.h的名称来源于意图兼容基于ISO/IEC 646字符集的键盘。ISO 646是1972年颁布的一项国际化的7位ASCII标准,规定了12个字符所对应的码位保持对各国标准开放:# $ @ [ \ ] ^ ` { | } ~

因此法国标准AFNOR NF Z 62010-1982把码位0x7c(ASCII码的 | )定义为ù,用法文键盘就难以输入C语言的位或运算符 | ;码位0x7e(ASCII码的 ~)定义为 ¨ (即分音符),法文键盘就难以输入C语言的位非运算符 ~ 。

加拿大法语标准CSA Z243.4-1985中把码位0x5e(ASCII码的 ^ )在定义为É,导致难以输入C语言的异或运算符 ^ 。

为解决上述的C语言源代码输入问题,C语言预处理器(C preprocessor)在扫描处理源文件时,使用三字符组替换为单个字符的办法。三字符组替换方法的可读性显然不如使用and、not等关键字。

参见

[编辑]

参考

[编辑]

外部链接

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
C替代标记
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?