至少内部名称的前31或63个字符是重要的?(At least the first 31 or 63 characters of an internal name are significant? [c

编程入门 行业动态 更新时间:2024-10-25 00:25:37
至少内部名称的前31或63个字符是重要的?(At least the first 31 or 63 characters of an internal name are significant? [closed])

以下是本书的直接引用(K&R,第2版,第35页):

“至少内部名称的前31个字符是重要的。对于函数名称和外部变量,数字可能小于31,因为外部名称可能被汇编程序和加载程序使用,语言无法控制。对于外部名称,该标准仅保证6个字符和一个案例。“

在C99中,其内部名称没有长度限制,但只有前63个保证是重要的(§5.2.4.1翻译限制)。

我的问题是为什么这些限制特别是3163 ? 为什么这个号码具体? 为什么不是19,24或任何其他数字? 如果这是一个实施问题,是否可以从3163获益?

Here's a direct quote from the Book (K&R, 2nd ed, p. 35):

"At least the first 31 characters of an internal name are significant. For function names and external variables, the number may be less than 31, because external names may be used by assemblers and loaders over which the language has no control. For external names, the standard guarantees only for 6 characters and a single case."

And in C99 there is no length limitation on its internal names, but only the first 63 are guaranteed to be significant (§5.2.4.1 Translation Limits).

My question is why are these limits specifically 31 or 63? Why this number specifically? Why not 19, 24 or any other number? If it's an implementation issue, is there a benefit from making it 31 or 63?

最满意答案

与语言设计委员会相关联的编译器/链接器编写器通常会施加一些限制,以便它们可以在工具链的实现中或在随附的二进制文件格式(例如, ELF , COFF等)中进行假设。 数字31和63的选择可能仅仅因为它们是2 n -1而程序员喜欢2 n因为某些愚蠢的原因。 -1通常用于说明名称中的前导_或尾随NUL字符。

The compiler/linker writers associated with a language design committee usually impose some limits so that they can make assumptions in the implementation of the toolchain or in the accompanying binary file formats (e.g., ELF, COFF, etc). The numbers 31 and 63 were probably chosen simply because they are 2n-1 and programmers like 2n for some silly reason. The -1 is usually to account for either a leading _ or a trailing NUL character in the name.

更多推荐

本文发布于:2023-07-24 00:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239295.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   名称   closed   internal   characters

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!