This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Strange behaviour of strchr in C++
- From: Mateusz Åoskot <mateusz at loskot dot net>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 28 Feb 2006 00:43:30 +0100
- Subject: Strange behaviour of strchr in C++
Hi,
I'd like to explan some issue with strchr function in C++.
AFAIK, there is only one version of strchr in ANSI C:
char * strchr ( const char * string, int c );
ANSI C++ standard specifies two versions:
const char * strchr ( const char * string, int c );
char * strchr ( char * string, int c );
Those two versions are specified *instead* of the one in ANSI C.
Now, I have two test programs: in C and in C++.
In both programs I try to use strchr in version from ANSI C.
1) gcc strchr.c -o strchrc
/* strchr.c file */
#include <stdio.h>
#include <string.h>
int main()
{
const char* c = "abc";
char* a;
a = strchr(c, 'b');
printf("%s\n", a);
return 0;
}
2) g++ strchr.cpp -o strchrcpp
// strchr.cpp file
#include <cstring>
#include <iostream>
int main()
{
const char* c = "abc";
char* a;
a = strchr(c, 'b');
std::cout << a << std::endl;
return 0;
}
So, I'd expect that g++ should give me an error message
because strchr usage is ambiguous but it compiles without any error.
I also tried to compile using g++ -pedantic but I got no error too.
My questions are:
Are my expectations correct and I should get error message?
Is this a bug in libstdc++?
Is this a bug in C++ standard?
How can I force g++ to comp
Here are some details about my environment:
[mloskot@wl ~]$ gcc --version
gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-54)
[mloskot@wl ~]$ ls /usr/lib/libstdc*
/usr/lib/libstdc++-2-libc6.1-1-2.9.0.so* /usr/lib/libstdc++.so.2.7.2.8*
/usr/lib/libstdc++-3-libc6.2-2-2.10.0.a /usr/lib/libstdc++.so.2.8@
/usr/lib/libstdc++-3-libc6.2-2-2.10.0.so* /usr/lib/libstdc++.so.2.8.0*
/usr/lib/libstdc++-libc6.1-1.so.2@ /usr/lib/libstdc++.so.2.9@
/usr/lib/libstdc++-libc6.2-2.a.3@ /usr/lib/libstdc++.so.2.9.dummy*
/usr/lib/libstdc++-libc6.2-2.so.3@ /usr/lib/libstdc++.so.5@
/usr/lib/libstdc++.so.2.7.2@ /usr/lib/libstdc++.so.5.0.3*
Cheers
--
Mateusz Åoskot
http://mateusz.loskot.net