我什么时候需要在 iso646.h 的 header 文件中使用按位和逻辑运算符的替代宏?

When do I need to use the alternative macros for bitwise and logical operators inside the header file of iso646.h?

我知道在iso646.h的header中,定义了以下11个宏常量来提供位运算符和逻辑运算符的替代描述:

and&&.

的宏

and_eq&= 的宏。

bitand&.

的宏

bitor|.

的宏

compl~ 的宏。

not!.

的宏

not_eq!= 的宏。

or||.

的宏

or_eq|=

的宏

xor^.

的宏

xor_eq^= 的宏。


但我什么时候需要使用这些替代宏?

如果您的编码没有实现完整的 ASCII 指令集,您应该使用它:

C derived its repertoire from the ASCII codeset. Unfortunately the ASCII repertoire is not a subset of all other commonly used character sets, and widespread practice in Europe is not to implement all of ASCII either, but use some parts of its collating sequence for special national characters.

The solution is an internationally agreed-upon repertoire, in terms of which an international representation of C can be defined. The ISO has defined such a standard: ISO 646 describes an invariant subset of ASCII.

The characters in the ASCII repertoire used by C and absent from the ISO 646 repertoire are:

    # [ ] { } \ | ~ ^

取自ANSI C Rationale, [2.2.1.1 Trigraph sequences]

正如@chqrlie 所指出的,这在 1980 年代是一个需要考虑的重要问题,但在今天却不那么重要了。

这也是引入三字母的原因(在同一部分中进一步解释)。因此,当使用非 ASCII 编码时,宏将替换为 iso646.h.

中的三字母版本