printf/fprintf 最大尺寸根据 c99

发布于 2024-12-15 06:09:34 字数 207 浏览 3 评论 0原文

C99 标准 说:

任何一次转换可以产生的字符数 至少应为 4095

这是否意味着最大尺寸为 4095 如果是,为什么它说“至少”?

The C99 standard says:

The number of characters that can be produced by any single conversion
shall be at least 4095

Does it mean that the maximum size is 4095 if yes why its says "at least"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

池予 2024-12-22 06:09:34

您已经发现了 C 语言规范中最令人烦恼的方面之一。他们通常不会说出最大值是多少。相反,他们通常会说出最大值的最小允许值是多少。

他们认识到不同的硬件/编译器/链接器环境有不同的限制,因此他们将大部分限制留给了各个工具作者。但是,他们希望在环境之间提供一定程度的可移植性,因此他们指定了最大值可以采用的最低值。

这就是我们如何得到限制,例如在消除符号歧义时只考虑标识符的前 8 个字符——他们不想强迫任何实现者处理更长的标识符,因此他们说“最小最大”长度是 8。

这是同样的故事 - 他们希望程序员能够使用适当大小的转换,但认识到某些平台可能无法处理巨大转换 - 因此他们设置了足够大的大小大多数程序员永远不知道关于限制,但足够小,以至于某些实现只能执行最低限度的操作并且仍然符合要求。

You've found one of the more annoying aspects of the C language specifications. They don't usually say what a maximum is. Instead, they'll usually say what the smallest allowed value for a maximum is.

They recognized that different hardware / compiler / linker environments have different restrictions, so they left most of the limits up to the individual tool authors. However, they wanted to provide some amount of portability between environments, so they specified the lowest values that maximums could take.

This is how we got restrictions like only the first 8 characters of identifiers being taken into account when disambiguating symbols -- they didn't want to force any implementor to deal with longer identifiers, so they said the "least maximum" length was 8.

It's the same story here -- they wanted programmers to be able to use decent-sized conversion, but recognized some platforms may not be able to handle huge conversions -- so they put in place a size large enough for most programmers to never know about the limit, but small enough that some implementations can do only the minimum and still be compliant.

老娘不死你永远是小三 2024-12-22 06:09:34

实现编译器必须允许至少 4095 个字符,但也允许更多。

Implementing compilers must allow at least 4095 characters but more is allowed.

芯好空 2024-12-22 06:09:34

“至少”意味着它是最小值,而不是最大值。

实现必须至少支持这么多,但可以支持更多。

"at least" means it is a minimum, not a maximum.

Implementations must support at least that much, but can support more.

随风而去 2024-12-22 06:09:34

C 标准没有指定最大值。他们所指定的是允许的最小值和最大值。

The C standard doesn't specify a maximum. What they do specify is the minimum value the maximum is allowed to be.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文