This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strtof is missing

Corinna Vinschen wrote:
On Sun, Nov 24, 2002 at 10:34:37AM +1000, Arseny Slobodjuck wrote:

Sunday, November 24, 2002, 9:04:04 AM, you wrote:

j> I use a pretty new Cygwin release and I notice that the strtof function is j> missing in stdlib.h. On my Linux system the function is declared in stdlib.h.

j> Can anybody help me? I should have to convert a string to a flat and this j> seems to be the only possibility. (O do not want to have double).

How about atof or sscanf ? That is two.

Or float f = (float) strtod ();

However, I just had a look into newlib and there's a function

float strtodf (const char *, char **);

defined. There's no man page on Linux and no such entry in SUSv3, but
it's the correct definition for strtof(3).
It looks like a typo, including stdlib.h. Or is there a good reason
for that definition?!?

It is not a typo.  Newlib was created to be ANSI with some Unix extensions.
Originally, strtodf was added in 1992 as an extension.  Since then, C99
has defined strtof.

Now, that said, since there is a strtof() routine defined in C99, we might
as well rename the extension.

The following is a patch which renames strtodf to be strtof and leaves a
#define mapping in stdlib for anybody using the old name.  Eventually, we should
be able to remove the old name entirely.

-- Jeff J.


Index: libc/include/stdlib.h
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.19
diff -u -r1.19 stdlib.h
--- libc/include/stdlib.h	26 Aug 2002 04:33:46 -0000	1.19
+++ libc/include/stdlib.h	4 Dec 2002 19:36:20 -0000
@@ -93,8 +93,9 @@
 _VOID	_EXFUN(srand,(unsigned __seed));
 double	_EXFUN(strtod,(const char *__n, char **__end_PTR));
 double	_EXFUN(_strtod_r,(struct _reent *,const char *__n, char **__end_PTR));
+float	_EXFUN(strtof,(const char *__n, char **__end_PTR));
 #ifndef __STRICT_ANSI__
-float	_EXFUN(strtodf,(const char *__n, char **__end_PTR));
+#define strtodf strtof
 long	_EXFUN(strtol,(const char *__n, char **__end_PTR, int __base));
 long	_EXFUN(_strtol_r,(struct _reent *,const char *__n, char **__end_PTR, int __base));
Index: libc/stdlib/strtod.c
RCS file: /cvs/src/src/newlib/libc/stdlib/strtod.c,v
retrieving revision 1.3
diff -u -r1.3 strtod.c
--- libc/stdlib/strtod.c	20 Apr 2001 22:50:51 -0000	1.3
+++ libc/stdlib/strtod.c	4 Dec 2002 19:36:20 -0000
@@ -12,7 +12,7 @@
         #include <stdlib.h>
         double strtod(const char *<[str]>, char **<[tail]>);
-        float strtodf(const char *<[str]>, char **<[tail]>);
+        float strtof(const char *<[str]>, char **<[tail]>);
         double _strtod_r(void *<[reent]>, 
                          const char *<[str]>, char **<[tail]>);
@@ -23,7 +23,7 @@
         char *<[str]>;
         char **<[tail]>;
-        float strtodf(<[str]>,<[tail]>)
+        float strtof(<[str]>,<[tail]>)
         char *<[str]>;
         char **<[tail]>;
@@ -48,7 +48,7 @@
 	(which will contain at least the terminating null character of
 	<[str]>) is stored in <<*<[tail]>>>.  If you want no
 	assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>.
-	<<strtodf>> is identical to <<strtod>> except for its return type.
+	<<strtof>> is identical to <<strtod>> except for its return type.
 	This implementation returns the nearest machine number to the
 	input decimal string.  Ties are broken by using the IEEE
@@ -721,11 +721,11 @@
-_DEFUN (strtodf, (s00, se),
+_DEFUN (strtof, (s00, se),
 	_CONST char *s00 _AND
 	char **se)
-  return _strtod_r (_REENT, s00, se);
+  return (float)_strtod_r (_REENT, s00, se);

Unsubscribe info:
Bug reporting:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]