gpt4 book ai didi

c - 多字节字符串和普通字符串

转载 作者:太空宇宙 更新时间:2023-11-04 01:27:48 25 4
gpt4 key购买 nike

我不明白对于 C 来说,每个字符串是否总是一个多字节字符串,这意味着它们被编码为多字节字符:

char s[] = "AAA"; 

char m[] = "X生";

如果 s 不包含像 m 这样的扩展字符集的成员,它也是一个多字节字符串吗?

我有这个疑问,因为我从 libc 手册中读到这个:

string” normally refers to multibyte character strings as opposed to wide character strings. Wide character strings are arrays of type wchar_t and as for multibyte character strings usually pointers of type wchar_t * are used.

所以我不明白 multibyte 是否指的是字符串的字节(它们的编号),以对宽字符串进行编码。

最佳答案

所以 C99 draft standard (C11 看起来一样)定义多字节字符如下:

sequence of one or more bytes representing a member of the extended character set of either the source or the execution environment

所以多字节字符是扩展字符集的一部分,所以s不是由多字节字符组成的。

多字节字符5.2.1.2部分进一步定义:

The source character set may contain multibyte characters, used to represent members of the extended character set. The execution character set may also contain multibyte characters, which need not have the same encoding as for the source character set. For both character sets, the following shall hold:

  • The basic character set shall be present and each character shall be encoded as a single byte.

  • The presence, meaning, and representation of any additional members is locales pecific.

  • A multibyte character set may have a state-dependent encoding, wherein each sequence of multibyte characters begins in an initial shift state and enters other locale-specific shift states when specific multibyte characters are encountered in the sequence. While in the initial shift state, all single-byte characters retain their usual interpretation and do not alter the shift state. The interpretation for subsequent bytes in the sequence is a function of the current shift state.

  • A byte with all bits zero shall be interpreted as a null character independent of shift state. Such a byte shall not occur as part of any other multibyte character.

关于c - 多字节字符串和普通字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28150386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com