This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [RFC] Should strtok_r be preferred to strtok?
- From: Nathan Myers <ncm-nospam at cantrip dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Mon, 25 Nov 2002 21:23:23 +0000
- Subject: Re: [RFC] Should strtok_r be preferred to strtok?
- References: <3DE2890E.1080509@unitus.it>
On Mon, Nov 25, 2002 at 09:33:18PM +0100, Paolo Carlini wrote:
> Wolfgang Bangerth, in private mail, pointed my attention to the the
> issue of thread-safety for strtok(), which I blatantly used in the
> rewrite of locale::_Impl::_Impl(const char* __s, size_t __refs) for
> thread safe :-( Posix localenames...
>
> Should we autoconf for strtok_r and prefer it when available?
There is no good reason to use any of these functions. The amount
of code in them is less than what you need to write yourself to use
them safely. In other words, you're better off re-implementing them
the right way. (Hint: instead of poking out the delimiter with a
NUL character as a terminator, how about using begin/end pointer
ranges, like a good C++ coder?)
No sarcasm intended. Thanks, Paolo, for giving me a nice opportunity
to vent on one of the most despicable bits of C89.
Nathan Myers
ncm-nospam@cantrip.org