Re: max size for printf() format conversion?



Matt Garman wrote:
Is there a clean, portable way to determine the maximum value of
converted numerical fields with printf()-like functions?  Doing this
at compile-time would be preferable.

For example, %i should never convert to a string that is longer than
the number of digits in INT_MAX, right?

I'd like to create a structure that contains character
representations of numerical types (e.g., instead of storing 3421 as
an int, it would store the char array "3421").  I'd like to make
these fields a fixed-size static array, but obviously I don't want
to make them too small.

C89: The draft I use states that a single conversion can produce a maximum of at least 509 characters. C99 (standard): This limit goes up to 4095 characters.

If in doubt, use snprintf()/vsnprintf() if available (and malloc()).

Cheers
 Michael
--
E-Mail: Mine is an   /at/ gmx /dot/ de   address.
.



Relevant Pages

  • max size for printf() format conversion?
    ... converted numerical fields with printf-like functions? ... at compile-time would be preferable. ... these fields a fixed-size static array, ... Matt Garman ...
    (comp.lang.c)
  • Re: max size for printf() format conversion?
    ... converted numerical fields with printf-like functions? ... such as some CRAY machines. ... I'd like to make these fields a fixed-size static array, but obviously I don't want to make them too small. ... You could write your own functions to do arithmetic on such strings, which would remove the limitation on their size. ...
    (comp.lang.c)
  • Re: max size for printf() format conversion?
    ... Matt Garman wrote: ... converted numerical fields with printf-like functions? ... %i should never convert to a string that is longer than ... are impossible to compute at compile time without ...
    (comp.lang.c)