jchitra
December 8, 2005, 11:41am
1
When I compiled the C code in gcc, it gave me some warnings.
But in g++, it is throwing the following error.
implicit declaration of function int strchr (…)
I have commented the #include <string.h> from my source.
How to solve this?
Help me to solve this error.
Jc
When tried with string.h, it gave the following Error.
/usr/include/string.h: In function void * memchr(void *, int, unsigned int)': /usr/include/string.h:126: passing
const void *’ as argument 1 of memchr(void *, int, unsigned int)' discards qualifiers /usr/include/string.h: In function
char * strchr(char *, int)’:
/usr/include/string.h:131: passing const char *' as argument 1 of
strchr(char *, int)’ discards qualifiers
/usr/include/string.h: In function char * strpbrk(char *, const char *)': /usr/include/string.h:136: passing
const char *’ as argument 1 of strpbrk(char *, const char *)' discards qualifiers /usr/include/string.h: In function
char * strrchr(char *, int)’:
/usr/include/string.h:141: passing const char *' as argument 1 of
strrchr(char *, int)’ discards qualifiers
/usr/include/string.h: In function char * strstr(char *, const char *)': /usr/include/string.h:146: passing
const char *’ as argument 1 of `strstr(char *, const char *)’ discards qualifiers
mario
December 9, 2005, 1:01pm
4
Funny I would have expect these fonctions to be declared as having const char. In fact if I look at the header file, they are defined as requiring pointer to const char.
Ex: extern _Const_return void *memchr( const void *__s, int __c, size_t __n );
Are you sure you have don’t have a screwed up string.h (like if somebody modified it). I’m looking at 6.3 header, but I would be VERY surprise if 6.2.1 header don’t use const char *.
I believe you need to add
using namespace std
or add -fhonor-std to your compile line
mario
December 10, 2005, 3:06am
6
he did say he got some warning in C
No, the mentioned g++ as the source of the errors.
Besides those errors are only generated by not having the namespace stuff right.