Strange behaviour of strchr in C++

Mateusz Łoskot mateusz@loskot.net
Tue Feb 28 01:16:00 GMT 2006


Joe Buck wrote:
> 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.

Yes, I think so.

> 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.

That's what I'm asking for.
So, in C++ program I should use C++ version of strchr, even if I can use 
C version without any error check.
And using C version of strchr in C++ program should be seen as 
incorrect. You know, someone can still argue "gcc compiles my code, so 
it's correct" and I'd like to be sure what should I tell her/him :-)

Best regards
-- 
Mateusz Łoskot
http://mateusz.loskot.net



More information about the Libstdc++ mailing list