"null character"可以用C语言表示为一个多字节值吗?

Can the "null character" be represented as a multibyte value in C language?

ANSI X3.159-1989“C 语言编程”标准在“5.2.1.2 - 多字节字符”一章中指出:

For both [source and execution] character sets the following shall hold:

  • A byte with all bits zero shall be interpreted as a null character independent of shift state.
  • A byte with all bits zero shall not occur in the second or subsequent bytes of a multibyte character.

这是否意味着对于翻译和执行环境,下一个语句是正确的?:

  1. 对于每个不同的转换状态,源字符集和执行字符集都可能有一个多字节值,用于表示空字符。 [想法:如果翻译或执行环境可以在不同的移位状态之间切换(可以不同的用于表示字符的字节数),那么它应该以某种方式检测空字符 - 不仅仅是来自的一个字节“空字符”基本字符集,但作为例如特定移位状态的两字节“空字符”。] P.S。这可能是对翻译和执行环境如何在字符串文字等中解释字符值的误解。
  2. 这些字符只能表示为第一个字节设置为“0”的值[即第一个字节,所有位为零],因此有多种表示方式:“FFFF 0000”、“ABCD 0000”等。
  3. “空字符”仅在基本 执行 字符集中定义。下面引用中的两条规则都适用于扩展 翻译和执行 字符集。因此,“空字符”的多字节表示可以在翻译和执行环境中使用,并且可以在不使用转义序列的情况下在源代码中使用多字节“空字符”,而是直接在某些代码中写入该字符一种文字。

或者“空字符”只能表示为单个字节值,并且是唯一一个由基本执行字符集定义的字符?

Does it mean that for the translation and execution environments next statements are true?:

Both source and execution character sets might have a multibyte value, used to represent the null character, for each different shift state.

没有。 “空字符”是一个定义的术语:

A byte with all bits set to 0, called the null character, shall exist in the basic execution character set [...]

在当前标准 (C17) 中的第 5.2.1/2 段中,但相同的文本一直追溯到 C89。

问题中引用的条款的要点是C实现不必关心移位状态或扩展字符来识别空字符,并且使用空字符作为字符串终止符不会导致截断任何多字节字符。

Those characters can be represent only as a values with the first byte set to "0" [i.e. first byte with all bits zero], so there is a wide range of how to represent it: "FFFF 0000", "ABCD 0000" and etc.

没有。同样,出于语言规范的目的,“空字符”是一个定义的术语,表示值为 0 的字节。讨论中的条款的要点是,在尝试识别空字符时,实现不需要考虑任何更广泛的上下文特点。例如,strcpy()strlen() 等字符串函数不需要知道或关心任何有关字符编码、移位状态或多字节字符的信息。他们只是通过空字符识别字符串的结尾。

The "null character" is defined only in the basic execution character set.

C 规范不要求源字符集具有空字符,但是您引用的文本说如果它包含值为 0 的 single-byte 字符,则该字符对于C的目的。

Both rules in a quote below are applicable to both extended translation and execution character sets.

是的。

So that, multibyte representation of the "null character" can be in both translation and execution environment, [...]

没有。同样,空字符是值为 0 的 byte,与字符集或编码无关。

Or the "null character" can only be represent as a single byte value, and its one and only such character, defined by the basic execution character set?

源字符集中也可以有空字符,但这不是必需的。并且每个扩展字符集都嵌入了相应的基本字符集,因此从这个意义上说,每个扩展执行字符集都定义了空字符,扩展源字符集也可以这样做。但是,在包含空字符的每个字符集中,该字符表示为值为零的字节,并且在任何字符表示中包含值为零的字节的每个字符集中,该字节表示空字符。