printf/fprintf maximum size according to c99

一个人想着一个人 提交于 2019-12-29 01:41:05

问题


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"?


回答1:


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.




回答2:


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




回答3:


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

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




回答4:


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



来源:https://stackoverflow.com/questions/8119914/printf-fprintf-maximum-size-according-to-c99

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!