最大字符串长度Maximum String Length

Microsoft 专用Microsoft Specific

ANSI 兼容性要求编译器在串联后接受字符串中最多 509 个字符。ANSI compatibility requires a compiler to accept up to 509 characters in a string literal after concatenation. Microsoft C 中允许的字符串的最大长度约为 2,048 个字节。The maximum length of a string literal allowed in Microsoft C is approximately 2,048 bytes. 但是,如果字符串由用双引号引起来的多个部分构成,则预处理器会将这些部分串联为一个字符串,对于串联的每个行,它会将一个额外的字节添加到总字节数。However, if the string literal consists of parts enclosed in double quotation marks, the preprocessor concatenates the parts into a single string, and for each line concatenated, it adds an extra byte to the total number of bytes.

例如,假设字符串包含 40 个行(其中,每行 50 个字符,共 2,000 个字符)和一个包含 7 个字符的行,并且每个行是由双引号引起来的。For example, suppose a string consists of 40 lines with 50 characters per line (2,000 characters), and one line with 7 characters, and each line is surrounded by double quotation marks. 所有这些字符共有 2,007 个字节,加上终止 null 字符的 1 个字节,总共为 2,008 个字节。This adds up to 2,007 bytes plus one byte for the terminating null character, for a total of 2,008 bytes. 在串联时,为前 40 个行中的每个行添加一个额外字符。On concatenation, an extra character is added for each of the first 40 lines. 这样将共有 2,048 个字节。This makes a total of 2,048 bytes. 但请注意,如果使用行继续符 (\) 代替双引号,则预处理器不会为每个行添加一个额外字符。Note, however, that if line continuations (\) are used instead of double quotation marks, the preprocessor does not add an extra character for each line.

单个带引号的字符串的长度不能多于 2048 个字节,可以通过串联多个字符串来构造一个长度约为 65535 个字节的字符串。While an individual quoted string cannot be longer than 2048 bytes, a string literal of roughly 65535 bytes can be constructed by concatenating strings.

结束 Microsoft 专用END Microsoft Specific

请参阅See Also

C 字符串文本C String Literals