can anybody tell me, why a program containing the function 'strcasestr'
(declared in 'string.h', case insensitive substring search)
compiles with gcc, but with g++ produces the error
implicit declaration of function `int strcasestr(...)' ?
What can i do in a c++ program (i don't want to use c++ library)
Thanks
Steffen Weinstock
Since strcasestr isn't defined by ISO C as a function declared in
<string.h>, it's quite possible that g++ being stricter about functions
that aren't specified by the Standard than gcc is. (Are you also getting
a warning about converting an int (the implicitly defined return value
of a non-prototyped function) to a pointer?) The C answer to this is
to explicitly prototype it before you use it, so that a prototype is
visible; you can probably also tell the compiler to look at the section
of <string.h> that it's declared in by defining an appropriate feature
selection macro before including it. I would assume (though I'm not
certain) that both of these would also work in C++.
dave
--
Dave Vandervies dj3v...@student.math.uwaterloo.ca
I really really wish Larry Wall was a native speaker of some language that
actually had rules. --Peter da Silva in the Scary Devil Monastery
> can anybody tell me, why a program containing the function 'strcasestr'
> (declared in 'string.h', case insensitive substring search)
> compiles with gcc, but with g++ produces the error
>
> implicit declaration of function `int strcasestr(...)' ?
strcasestr() is not an ISO function. Apparently, your g++ is set to
adhere more closely to the ISO Standard than your gcc. Try using -Wall
-pedantic.
Richard
'strcasestr()' is not a standard C function. Are you sure that
it is declared in 'string.h'. If you compile with the option -ansi
then it is probable the the declaration will be 'ifdef'ed out even
if it exists in the header.
By the C89/90 standards a diagnostic is not required for
implicit declarations and will only be given by gcc (compiling C)
if you select an option that turns it on.
I'm not too familiar with C++ but suspect it always requires a
diagnostic for implicit declarations.
In other words I suspect that the declaration is implicit in both
cases but only reported for C++.
Malcolm Kay
>Hi,
>
>can anybody tell me, why a program containing the function 'strcasestr'
>(declared in 'string.h', case insensitive substring search)
The standard C library doesn't define any function called strcasrstr
so it is quite possible that it is not defined in <string.h>.
>compiles with gcc, but with g++ produces the error
The C language (at least prior to C99) does not require a compiler
to diagnose a call to an undeclared function, C++ does.
> implicit declaration of function `int strcasestr(...)' ?
This suggests that this function is not declared in <string.h>, at least
not under all conditions.
>What can i do in a c++ program (i don't want to use c++ library)
Either determine that your implementation does support strcasestr as an
extension and check your documentation for the correct way to provide
a declaration for it, or else don't use strcasestr at all perhaps define
your own function that converts its input strings to a common case
(probably using loops and toupper() or tolower() ) and then call
strstr(). This second approach has the advantage of being portable.
--
-----------------------------------------
Lawrence Kirby | fr...@genesis.demon.co.uk
Wilts, England | 7073...@compuserve.com
-----------------------------------------
>'strcasestr()' is not a standard C function. Are you sure that
>it is declared in 'string.h'. If you compile with the option -ansi
>then it is probable the the declaration will be 'ifdef'ed out even
>if it exists in the header.
Why? The name strcasestr is in the implementation name space, so
<string.h> can declare it even when the compiler is invoked in
conforming mode.
Dan
--
Dan Pop
CERN, IT Division
Email: Dan...@cern.ch
Mail: CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland
Ta',
Juergen
--
\ Real name : Juergen Heinzl \ no flames /
\ EMail Private : jue...@monocerus.demon.co.uk \ send money instead /
I don't know why, you should ask the implementers this. But
certainly the string.h header file on my system guards similar
functions with:
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
/*various non-standard function prototypes including strcasecmp() */
/* (however strcasestr() is not known on the system */
#endif
That's neither needed nor universal practice. On my system:
ues5:~/tmp 188> cat test.c
#include <string.h>
int main()
{
strcasecmp("foo", "bar");
return 0;
}
ues5:~/tmp 189> gcc -Wall -ansi -pedantic test.c
ues5:~/tmp 190>
As for strcasestr(), it is a glibc extension. To get its declaration in
scope, you have to define the _GNU_SOURCE macro (assuming that you have
glibc and its headers installed on your system).
I realise it is not needed and not universal; however it seems to be
not uncommon.
>
> ues5:~/tmp 188> cat test.c
> #include <string.h>
>
> int main()
> {
> strcasecmp("foo", "bar");
> return 0;
> }
> ues5:~/tmp 189> gcc -Wall -ansi -pedantic test.c
> ues5:~/tmp 190>
>
> As for strcasestr(), it is a glibc extension. To get its declaration in
> scope, you have to define the _GNU_SOURCE macro (assuming that you have
> glibc and its headers installed on your system).
No, I don't have glibc and its headers. The C library is from Berkley
BSD 4.4
lite. The prime compiler is however gcc.
Malcolm Kay