I'd expect the endptr
to point to the same value with both strtod()
and strtold()
. Yet they differ. I suspect strtold()
is incorrect. OTOH, this could be a case where the spec is not clear and either result is acceptable.
Is this a bug (and with which function) or undefined/unspecified behavior?
Using: gcc\x86_64-pc-cygwin\4.8.3
#include <math.h>
#include <stdio.h>
// Edit - This include is in my true code, but was missing in original post
#include <stdlib.h>
int main(void) {
char *s = "123ez";
char *endptr;
double d = strtod(s, &endptr);
printf(" double %f '%s'\n", d, endptr);
long double ld = strtold(s, &endptr);
printf("long double %Lf '%s'\n", ld, endptr);
return 0;
}
Output:
double 123.000000 'ez'
long double 123.000000 'z'
[Edit]
gcc comand gcc -I"C:\cygwin64\lib\gcc\x86_64-pc-cygwin\4.8.3\include" -O0 -g3 -Wall -c -fmessage-length=0 -std=c99 -MMD -MP -MF"string_fp.d" -MT"string_fp.d" -o "string_fp.o" "../string_fp.c"
GCC 4.9.2