what is the limit of memory that printf can utilize for storing its computed arguments?
What is the general memory size available for any command (with variable no. of arguments), to store its arguments?
Example code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
//by default the decimal is considered as double
float a = 0.9;
//long double b = (long double)23455556668989898988988998898999.99 ;
long double b = 5.32e-5;
double z = 6789999000000.8999;
//b = (long double)1.99999999;
printf("float %f, \n double %lf,\n long double %Lf\n\n\n", b, b, b);
printf("simple: long double %Lf, double %lf, float %f\n\n\n", b,b,b);
printf(" sumi: float %f, double %lf, long double %Lf\n\n\n", z, z, z);
printf("test2 for le/lg/lf: dbl f %Lf, double g %Lg, double e %Le\n\n\n", b, b, b);
system("PAUSE");
return 0;
}
The minimum memory requirements for
printfto support printing any of the types you can pass to it is about 6k of stack space, assuming 15-bit exponent onlong double. For any non-floating-point type, you could get by with 200 bytes or less.Of course most real-world implementations are not maximally-efficient here. glibc at least performs
mallocas part ofprintf, at least for some formats, and thus has unpredictable failure cases. As far as I can tell this is just lazy coding… No idea what MS’sprintfdoes but I wouldn’t expect quality code there either…