On 2020-01-07 20:40, Vincent Torri wrote:
hello

have you looked at the exemple at the bottom of that page :

https://linux.die.net/man/3/strtol

Sure. My code works on linux using gnu compilers but does not work in mingw64 using (more or less) the same compilers and the results differ. Below is a a tiny complete test program which demonstrates the issue showing the issue, just cut and paste the indicated region into a bash shell on linux and mingw64

#start cut here
cat >errno_prob.c <<'EOD'
/*
    Build with:

       gcc -Wall -std=c99 -pedantic -o errno_prob errno_prob.c

    Run with

       errno_prob "1.0e+40"  #overflow test

*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>


int main(int argc,char **argv){
   char *final;
   errno=0;
   float fv = strtof(argv[1],&final);
fprintf(stderr,"DEBUG buffer %p final %p fv %f errno %d\n",argv[1],final,fv, errno);
   fflush(stderr);
   exit(EXIT_SUCCESS);
}
EOD
gcc -Wall -std=c99 -pedantic -o errno_prob errno_prob.c
./errno_prob "1.0e+40"
#end cut here

Outputs from the two systems:

linux: DEBUG buffer 0x7ffdb3ad8ee0 final 0x7ffdb3ad8ee6 fv inf errno 34 mingw64: DEBUG buffer 000000000068F970 final 000000000068F977 fv 1.#INF00 errno 0

The only significant difference is that errno is not set in the mingw64 one. It should be though, because 1.0e+40 is an ERANGE state, as correctly indicated on linux. No input I tried would make errno something other than 0. These were tried:

1.0e+40
blech
.000000000000000000000000000000000000000000000000001
1000000000000000000000000000000000000000000000000000
1.0e-100

So why is errno not set in mingw64?

Thanks,

David Mathog
mat...@caltech.edu
Manager, Sequence Analysis Facility, Biology Division, Caltech


_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to