printf/fprintf maximum size according to c99

前端 未结 4 1681
名媛妹妹
名媛妹妹 2020-12-11 20:35

The C99 standard says:

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

Does it m

相关标签:
4条回答
  • 2020-12-11 20:54

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

    0 讨论(0)
  • 2020-12-11 20:56

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

    0 讨论(0)
  • "at least" means it is a minimum, not a maximum.

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

    0 讨论(0)
  • 2020-12-11 21:12

    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.

    0 讨论(0)
提交回复
热议问题