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 had to deal in past with several standard printf
implementations and my general impression that there is no particular limit imposed.
The format string generally is parsed character by character. (Think simple FSM.) Most printf
implementations avoid buffering anything internally and even for numbers use the char by char conversion to decimal (not even atoi
).
You can check for example how the printf
is implemented inside the FreeBSD kernel (where from many other implementations often lift the code). That is surely simplified implementation (with couple kernel-specific tweaks), yet it reflects how the format string is often handled.
N.B. Just checked glibc's vfprintf()
implementation and they allocate internally a buffer (if needed) with malloc()
. So neither particular limit there.
My question is, what is the length of the maximal single specification in a format string that can be created, according to C99 standard?
The format specifier is a part of a string and string length to my knowledge isn't limited by the standard. And as I mention above, neither I have ever seen an implementation with any such limit.
snprintf
and want to understand whether i can allocate some temporary buffers statically – Caledonian