Topic: strchr should be fixed in the standard
Author: Mark Jones <mark@booksys.com>
Date: 1997/05/06 Raw View
myfunc(const char *s)
{
char *d = strchr(s, 'c');
.
.
.
*d = 0; // violates the const char * protection
}
The above code is subtle and should be flagged by the compiler. But
won't be because of the way that strchr is declared.
Has anyone given thought to having two version of strchr?
const char *strchr(const char *s, int c)
and
char *strchr(char *s, int c)
This is one that could not be fixed in C because there is no
overloading. However this one could be fixed in C++
Comments? Is this old news?
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/05/07 Raw View
Mark Jones <mark@booksys.com> writes:
>Has anyone given thought to having two version of strchr?
>
>const char *strchr(const char *s, int c)
>and
>char *strchr(char *s, int c)
...
>Comments? Is this old news?
Yes, it is old news: not only has this been considered, it is indeed
part of the C++ draft working paper. Similarly there are two versions
of strrchr(), strpbrk(), strstr(), memchr(), wcschr(), wcsrchr(),
wcsstr(), and wmemchr(). See 21.4 [lib.c.strings] in the DWP.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]