question about strstr() in g++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

My understanding is that in C++ two overloaded versions of strstr() should be defined:

const char * strstr ( const char * str1, const char * str2 );
      char * strstr (       char * str1, const char * str2 );

(http://www.cplusplus.com/reference/clibrary/cstring/strstr/ but also Stroustrup's book section 20.4.1 (special edition))

The way I read this, the following C++ code should be invalid:

#include <cstring>
char *backdoor(const char *a, const char *b)
{
        return std::strstr(a, b);
}

since it is trying to remove the const-ness of the std:strstr() result. However, g++ accepts this. It doesn't even give a warning with g++ -ansi -Wall -W -pedantic. Most compilers I tried accept this, but it is my understanding that VS08 rejects this code.

So am I reading this wrong, or is there a bug in g++?


Thanks!

Peter.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux