Strange behaviour of strchr in C++

Joe Buck Joe.Buck@synopsys.COM
Tue Feb 28 00:56:00 GMT 2006


On Tue, Feb 28, 2006 at 01:53:26AM +0100, Mateusz Łoskot wrote:
> So, what is a recommended way of handling this issue today?
> I mean, is it bettern to not to use C version of strchr in
> C++ programs even if g++ allows to use it?

It's not as bad as it appears to you.

Just include <cstring> and call strchr as if the correct prototypes
were provided.  For valid code, the right thing will happen.  The
only issue is that the compiler will not detect cases where you
use strchr to silently get a char* from a const char*.  So all you
really lose is an error check.



More information about the Libstdc++ mailing list