[comp.lang.c] strange behavior from SUN strtod

magostin@procase.UUCP (Mike Agostino) (07/20/88)

I seemed to have discovered a bug in the SUN library function strtod().  Can anyone confirm
this?  Here is a sample program:

#include <stdio.h>
main() {

static char *real = "  1.2x",*p;
double a;
extern double strtod(); 

a = strtod(real,&p);
printf("a = %f\n\n",a);
printf("*p = %c\n\n",*p);
}

	It seems to me that the output of this program should be similiar to:

149 <//c/u/magostin>a.out
a = 1.200000

*p = x

150 <//c/u/magostin>

This output is from Apollo's C compiler which seems to correctly intepret the standard.
The problem w/ the Sun strtod() lies in that the second parameter is not correctly 
passed back.  It should point at the first non-numeric character in the string.  (in this
example the 'x') However, on the SUN the second parameter remains pointing to the beginning
of the string.  Any comments on this behavior?  Have I made a mistake?  Please 
email me, I will post to the net if sufficient response.

thanks for any help

mike agostino
...{hpda,tolerant,cae780}!procase!magostin

paul@arthur.uchicago.edu (Paul Burchard) (07/21/88)

In article <3d59d9c1.14de1@simscript> magostin@procase.UUCP (Mike Agostino) writes:
>I seemed to have discovered a bug in the SUN library function strtod().  Can anyone confirm
>this?  Here is a sample program:
  [deleted]
>The problem w/ the Sun strtod() lies in that the second parameter is not correctly 
>passed back.
  [...]
>
>mike agostino


Yes, I've had the same problem.  Ended up moving the pointer by hand (humph).
We're running Sun UNIX 4.2 Release 3.3; don't know about later versions.


-----------------------------------------------------------------------------
Paul Burchard	paul@zaphod.UChicago.Edu
``This quote intentionally devoid of meaning'' -- D. Void
-----------------------------------------------------------------------------

guy@gorodish.Sun.COM (Guy Harris) (07/22/88)

> >I seemed to have discovered a bug in the SUN library function strtod().`
> >Can anyone confirm this?  Here is a sample program:
>   [deleted]
> >The problem w/ the Sun strtod() lies in that the second parameter is not
> >correctly passed back.

The answer is "yes, he's found a bug in the AT&T System V Release 2.0 library
function 'strtod()'" (the Sun one is just the S5R2 one, with one #ifdef changed
to correctly specify which machines are IEEE machines).  You'll find this bug
on machines other than Suns....

> Yes, I've had the same problem.  Ended up moving the pointer by hand (humph).
> We're running Sun UNIX 4.2 Release 3.3; don't know about later versions.

AT&T's bug is fixed in S5R3, I think, or perhaps sooner.  Sun's bug is fixed in
4.0; the two implementations are now different.