Topic: strtod


Author: "Mycroft Holmes" <holmes@technologist.com>
Date: Mon, 5 Mar 2001 16:28:53 GMT
Raw View
Two questions:

1] is the function "double strtod(const char* strng, char ** stopchar)"
strictly standard c++?

2] assuming 1 is true, is it standard to "work in place" passing stopchar =
&strng ?
--
 The set of solutions is never empty.
 Two solutions together form a new problem.
-- Mycroft Holmes


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Ron Natalie <ron@spamcop.net>
Date: Mon, 5 Mar 2001 21:33:57 GMT
Raw View

Mycroft Holmes wrote:
>
> Two questions:
>
> 1] is the function "double strtod(const char* strng, char ** stopchar)"
> strictly standard c++?

Yes.  It's part of the C library and thus is inherited in C++.

>
> 2] assuming 1 is true, is it standard to "work in place" passing stopchar =
> &strng ?
> --
You can do that if you want.  The value of strng is passed by value, so by
the time you get into the body of strtod, there the strng is potentially
expendable.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Victor Bazarov" <vAbazarov@dAnai.com>
Date: Mon, 5 Mar 2001 15:34:18 CST
Raw View
"Mycroft Holmes" <holmes@technologist.com> wrote...
> Two questions:
>
> 1] is the function "double strtod(const char* strng, char **
stopchar)"
> strictly standard c++?

Yes, it is.

> 2] assuming 1 is true, is it standard to "work in place" passing
stopchar =
> &strng ?

Yes, it is.  There is nothing in the C Standard that would say
that it's not OK.  Besides, the pointer value 'strng' is copied
to create the first parameter, so even if you pass its address
as the second argument the first parameter is not affected by
that.

Victor
--
Please remove capital A's from my address when replying by mail



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Jack Klein <jackklein@spamcop.net>
Date: Tue, 6 Mar 2001 04:03:03 GMT
Raw View
On Mon,  5 Mar 2001 16:28:53 GMT, "Mycroft Holmes"
<holmes@technologist.com> wrote in comp.std.c++:

> Two questions:
>
> 1] is the function "double strtod(const char* strng, char ** stopchar)"
> strictly standard c++?
>
> 2] assuming 1 is true, is it standard to "work in place" passing stopchar =
> &strng ?

As others have said, you can do this but if you do you lose one of the
valuable properties of the strto... functions.  That is the ability to
easily tell the difference between unconvertible data or an actual
text representation that evaluates to 0 (or 0.0).

Consider:

char *endptr;

char data [/*some size*/];

double d;

/* some code to get input into data */

d = strtod(data, &endptr);

if (d == 0.0)
{
   if (endptr == data)
   {
       // output invalid data entered message
   }
   else
   {
       // data actually says "0"
   }
}

If you don't keep the original pointer around, there is no way to tell
the difference.

--
Jack Klein
Home: http://JK-Technology.Com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]