| www.delorie.com/djgpp/bugs/show.cgi | search |
atof() and strtod() do not clean up the FP stack. After 8 calls to either
or a few calls followed by other FP stack usage, the stack overflows.
This occurs also with the newer libm.a version that fixes other problems.
#include <stdio.h>
#include <math.h>
// demo of atof() and strtod() FP stack problem
void main()
{
double a[9];
char *ainit = "3.1415";
int i;
for (i = 0; i < 9; i++) // FP stack is 8 deep
{
a[i] = atof(ainit); //overflows FP stack
//a[i] = strtod(ainit); //overflows FP stack
//sscanf(ainit, "%lf", &(a[i]));//works
}
printf("last value was %f\n", a[8]);
}sscanf seems to work as a substitute for atof. double var; sscanf(buffer, "%lf", &var);
This looks like a consequence of bug 80 which is fixed in WIP.
Never again will I confuse -w (compiler warnings off) with -W (extra warnings)!! Had I not had -w checked, I would have spotted the implicit declarations of atof, etc. noticed that I needed <stdlib.h>, not <math.h>, found that strtod was missing a parameter, and saved myself a lot of time. (atof returned result on FP stack, int result was expected in EAX, hence no pop. I hope no one else wasted much time on this. Please remove this bogus bug from the system. If you feel that moving it to the closed section as a warning to other foolish mortals would serve the common good, I can live with that ... I guess. - regards, tom.
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2010 by DJ Delorie | Updated Jul 2010 |