delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/12/04/14:47:56

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <3DEE5BD8.5000408@redhat.com>
Date: Wed, 04 Dec 2002 14:47:36 -0500
From: "J. Johnston" <jjohnstn AT redhat DOT com>
Organization: Red Hat Inc.
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Corinna Vinschen <cygwin AT cygwin DOT com>
Cc: newlib AT sources DOT redhat DOT com
Subject: Re: strtof is missing
References: <200211240004 DOT 04863 DOT jblazi AT gmx DOT de> <177909597 DOT 20021124103437 AT vtc DOT ru> <20021124105015 DOT X1398 AT cygbert DOT vinschen DOT de>

--------------080405060909070602090604
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

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.

> Corinna
> 


--------------080405060909070602090604
Content-Type: text/plain;
 name="strtof.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="strtof.patch"

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
 #endif
 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 @@
 ANSI_SYNOPSIS
         #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 @@
 }
 
 float
-_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);
 }
 
 #endif


--------------080405060909070602090604
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--------------080405060909070602090604--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019