printf
conversion specifications are %
followed by flags, width, precision, length modifier and conversion specifier. Is there practical limit to size of a conversion specification?
I.e. %s
is 2 chars long, while %08.2f
is 6 chars long. My question is, what is the length of the maximal single specification in a format string that can be created, according to C99 standard?
There is no such conversion specification of maximum length. If you think you've found such a spec, I can come up with one that is one char longer.
For example, consider field width and precision. The standard says they are decimal integers but does not specify their range. Therefore you can write conversion specifiers with arbitrarily large integers as field width or precision.
If you mean a literal string, it's 4095 characters
5.2.4.1 Translation limits
...
-- 4095 characters in a character string literal or wide string literal (after concatenation)
...
I've been bitten by C89 limit of 509 characters (not for printf/scanf format strings), so this is one of the good changes brought on by C99 :-)
Edit: glibc implementation (not Standard definition)
glibc implementation gets the width from a read_int
function.
So, for this implementation, apparently, maybe, the limit is INT_MAX (I haven't searched for the read_int
function).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With