Re: question about strstr() in g++

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

 



On 08/23/2009 09:32 PM, Peter van Hoof wrote:
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++?

GCC 4.4.1:

  In function 'char* backdoor(const char*, const char*)':
  error: invalid conversion from 'const char*' to 'char*'

So it seems you're using an old GCC which has this bug.


[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