Re: max size for printf() format conversion?
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Tue, 31 May 2005 22:31:07 +0200
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. .
- References:
- max size for printf() format conversion?
- From: Matt Garman
- max size for printf() format conversion?
- Prev by Date: Re: max size for printf() format conversion?
- Next by Date: Re: Formatted IO; %d or %i?
- Previous by thread: Re: max size for printf() format conversion?
- Next by thread: undefined reference uuid_parse
- Index(es):
Relevant Pages
|