This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH] Fix hpux10 string to real conversion defficiences
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- To: fxcoudert at gmail dot com (FX Coudert)
- Cc: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org, burnus at net-b dot de
- Date: Fri, 11 Apr 2008 09:56:07 -0400 (EDT)
- Subject: Re: [PATCH] Fix hpux10 string to real conversion defficiences
> > +static float
> > +gfc_strtof (const char *s, char **p)
> > +{
> > +#if ((defined(HAVE_STRTOF) && defined(HAVE_BROKEN_STRTOF)) \
> > + || defined(HAVE_BROKEN_STRTOD))
> > + const char *s1 =3D s;
> > + int plus =3D 1;
> > +
> > + if (*s1 =3D=3D '+')
> > + s1++;
> > + else if (*s =3D=3D '-')
> > + {
> > + s1++;
> > + plus =3D 0;
> > + }
> > +
> > + if (nan_p (s1))
> > + return plus ? __builtin_nanf ("") : -__builtin_nanf ("");
> > + else if (inf_p (s1))
> > + return plus ? __builtin_inff () : -__builtin_inff ();
> > +#endif
>
> If you have HAVE_STRTOF and HAVE_BROKEN_STRTOF, you end up with the
> following "return" being dead code. I suggest changing the above
> "#endif" into an "#else" (and adding another "#endif" at the end of
> the function).
>
> > +
> > +#if defined(HAVE_STRTOF)
> > + return strtof (s, p);
> > +#else
> > + return (float) strtod (s, p);
> > +#endif
> > +}
I don't believe the code is dead. It is used for all conversions except
"nan", "inf" and "infinity". There are some differences between the
three cases becauses strtod is always assumed to be available.
I'll make the other changes. I thought __attribute__((unused)) had
to appear on a function's declaration, but I'll recheck.
It is my understanding that that leading whitespace has been stripped
already. From my reading of the strtod manpage on linux and hpux,
there can't be trailing whitespace. There is an issue with the string
representation of NANs. From the linux manpage for strtod,
A NAN is "NAN" (disregarding case) optionally followed by '(', a
sequence of characters, followed by ')'. The character string speci-
fies in an implementation-dependent way the type of NAN.
The optional stuff is not supported on hpux11, and it is implementation
dependent on linux. Do you have guidance on whether this is supported
in fortran?
Dave
--
J. David Anglin dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6602)