Topic: strto{d,l,ul} overloading?
Author: scott douglass <sdouglass%_%junk@_.arm.com>
Date: 1999/04/16 Raw View
James Kuyper wrote:
>
> scott douglass wrote:
> >
> > Hello,
> >
> > I was surprised not to find const char* overloadings of strtod, strtol and
> > strtoul to replace the "mixed constness" versions in C, similarly to the way
> > that strstr has been overloaded, e.g.:
> >
> > double strtod(char *, char **);
> > double int strtod(const char *, const char **);
> > long strtol(char *, char **, int);
> > long strtol(const char *, const char **, int);
> > unsigned long strtoul(char *, char **, int);
> > unsigned long strtoul(const char *, const char **, int);
> >
> > Is there a way (that is more official than posting here) to suggest they be
> > added for next time?
> >
> > Or, is there a problem with doing this that I'm overlooking?
>
> It's not that there's a problem; it's that your suggested change isn't
> needed. The functions you list are already const on all of their pointer
> arguments, so they already be used with either const or non-const
> pointer arguements.
>
> The functions that were overloaded are the ones that return a pointer.
I disagree. In C these functions do "return" a non-const pointer formed from
their
first argument. They "return" it by assigning through their second parameter.
This
is what I meant by "mixed constness".
The C prototypes (from stdlib.h) are:
double int strtod(const char *, char **);
long strtol(const char *, char **, int);
unsigned long strtoul(const char *, char **, int);
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/04/18 Raw View
scott douglass wrote:
>
> James Kuyper wrote:
....
> > The functions that were overloaded are the ones that return a pointer.
>
> I disagree. In C these functions do "return" a non-const pointer formed from
> their
> first argument. They "return" it by assigning through their second parameter.
> This
> is what I meant by "mixed constness".
> The C prototypes (from stdlib.h) are:
>
> double int strtod(const char *, char **);
> long strtol(const char *, char **, int);
> unsigned long strtoul(const char *, char **, int);
Sorry - you're right. The definitions of those functions aren't in the
C++ standard itself, so I hadn't bothered to look them up. Now that I've
checked their definitions, I agree that overloaded versions with the
second argument also declared 'const char **' would be useful.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: scott douglass <sdouglass%_%junk@_.arm.com>
Date: 1999/04/15 Raw View
Hello,
I was surprised not to find const char* overloadings of strtod, strtol and
strtoul to replace the "mixed constness" versions in C, similarly to the way
that strstr has been overloaded, e.g.:
double strtod(char *, char **);
double int strtod(const char *, const char **);
long strtol(char *, char **, int);
long strtol(const char *, const char **, int);
unsigned long strtoul(char *, char **, int);
unsigned long strtoul(const char *, const char **, int);
Is there a way (that is more official than posting here) to suggest they be
added for next time?
Or, is there a problem with doing this that I'm overlooking?
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/04/16 Raw View
scott douglass wrote:
>
> Hello,
>
> I was surprised not to find const char* overloadings of strtod, strtol and
> strtoul to replace the "mixed constness" versions in C, similarly to the way
> that strstr has been overloaded, e.g.:
>
> double strtod(char *, char **);
> double int strtod(const char *, const char **);
> long strtol(char *, char **, int);
> long strtol(const char *, const char **, int);
> unsigned long strtoul(char *, char **, int);
> unsigned long strtoul(const char *, const char **, int);
>
> Is there a way (that is more official than posting here) to suggest they be
> added for next time?
>
> Or, is there a problem with doing this that I'm overlooking?
It's not that there's a problem; it's that your suggested change isn't
needed. The functions you list are already const on all of their pointer
arguments, so they already be used with either const or non-const
pointer arguements.
The functions that were overloaded are the ones that return a pointer.
You sometimes need to get a non-const pointer returned from those
functions. Two versions are provided, one returning const and the other
non-const. You're not allowed to overload on return type, so those two
functions are given different signatures by having the one which returns
a const pointer, be the one taking a const pointer argument. This
usually works out fairly well, because in the case where you need a
non-const pointer returned, that pointer usually points into the same
object as the corresponding non-const pointer arguement.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]