首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Alternative operators and tokens

C 源代码可以用任何包含 ISO 646:1983不变字符集的非 ASCII 8位字符集编写。但是,几个 C 操作符和标点符号需要 ISO 646代码集之外的字符:{, }, [, ], #, \, ^, |, ~。为了能够使用其中部分或全部符号不存在的字符编码(例如德国 DIN 66003),有两种可能性:使用这些字符的操作符的替代拼写或两个或三个 ISO 646兼容字符的特殊组合这被解释为它们是单个非 ISO 646字符。

运算符宏(C95)

对于使用以 ISO <iso646.h>宏定义的非 ISO646字符的操作符,还有其他拼写方式:

| Defined in header <iso646.h> |

|:----|

| Primary | Alternative |

| && | and (macro constant) |

| &= | and_eq (macro constant) |

| & | bitand (macro constant) |

| | | bitor (macro constant) |

| ~ | compl (macro constant) |

| ! | not (macro constant) |

| != | not_eq (macro constant) |

| || | or (macro constant) |

| |= | or_eq (macro constant) |

| ^ | xor (macro constant) |

| ^= | xor_eq (macro constant) |

字符&!是不变的 ISO-646下,但提供了使用这些字符无论如何,以适应更加严格的历史字符集运营商的替代品。

eq对于相等运算符没有其他拼写(如),==因为该字符=出现在所有支持的字符集中。

Alternative tokens(C95)

以下替代令牌是核心语言的一部分,并且在各方面的语言中,每个替代令牌的行为与其主令牌完全相同,但其拼写(字符串操作符可以使拼写可见)除外。两个字母的替代令牌有时被称为“二元符号”

Primary

Alternative

{

<%

}

%>

[

<:

]

:>

%:

%:%:

Trigraphs

在识别注释和字符串文字之前,会分析以下三个字符组(trigraphs),并且每个三角形的外观都会被相应的主要字符替换:

Primary

Trigraph

{

??<

}

??>

[

??(

]

??)

??=

\

??/

^

??'

|

??!

~

??-

由于 trigraphs 被提前处理,所以注释// Will the next line be executed?????/会有效地注释掉下面的行,并将字符串文字(比如"What's going on??!"被解析为)注释掉"What's going on|"

以下示例演示了<iso646.h>头文件中的替代运算符拼写以及使用二元和三元符。

第一个命令行参数 argv1中的空格字符需要引号:“,World!”。

代码语言:javascript
复制
%:include <stdlib.h>
%:include <stdio.h>
%:include <iso646.h>
 
int main(int argc, char** argv)
??<
    if (argc > 1 and argv<:1:> not_eq NULL)
    <%
       printf("Hello%s\n", argv<:1:>);
    %>
 
    return EXIT_SUCCESS;
??>

可能的输出:

代码语言:javascript
复制
Hello, World!

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com