Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

strcasestr()

899 views
Skip to first unread message

Steffen Weinstock

unread,
Apr 23, 2001, 3:52:50 AM4/23/01
to
Hi,

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

Dave Vandervies

unread,
Apr 23, 2001, 4:46:14 AM4/23/01
to
In article <3AE3DF52...@thphys.uni-heidelberg.de>,

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

Richard Bos

unread,
Apr 23, 2001, 6:54:52 AM4/23/01
to
Steffen Weinstock <S.Wei...@thphys.uni-heidelberg.de> wrote:

> 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

Mal Kay

unread,
Apr 23, 2001, 10:36:27 AM4/23/01
to


'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

Lawrence Kirby

unread,
Apr 23, 2001, 8:57:53 AM4/23/01
to
In article <3AE3DF52...@thphys.uni-heidelberg.de>
S.Wei...@thphys.uni-heidelberg.de "Steffen Weinstock" writes:

>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
-----------------------------------------

Dan Pop

unread,
Apr 23, 2001, 4:03:14 PM4/23/01
to

>'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

Juergen Heinzl

unread,
Apr 23, 2001, 6:16:58 PM4/23/01
to
In article <988030...@genesis.demon.co.uk>, Lawrence Kirby wrote:
>In article <3AE3DF52...@thphys.uni-heidelberg.de>
> S.Wei...@thphys.uni-heidelberg.de "Steffen Weinstock" writes:
>
>>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>.
[-]
It may be declared, but ...

>
>>compiles with gcc, but with g++ produces the error
[-]
... use -D_GNU_SOURCE. If it still doesn't compile, then you're
either out of luck or ...
[-]

>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.
[-]
...

Ta',
Juergen

--
\ Real name : Juergen Heinzl \ no flames /
\ EMail Private : jue...@monocerus.demon.co.uk \ send money instead /

Mal Kay

unread,
Apr 24, 2001, 11:12:45 AM4/24/01
to
Dan Pop wrote:
>
> In <3AE43DEB...@adelaide.on.net> Mal Kay <malco...@adelaide.on.net> writes:
>
> >'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.
>

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

Dan Pop

unread,
Apr 24, 2001, 1:16:06 PM4/24/01
to

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).

Mal Kay

unread,
Apr 27, 2001, 6:36:41 AM4/27/01
to
Dan Pop wrote:
>
> In <3AE597ED...@adelaide.on.net> Mal Kay <malco...@adelaide.on.net> writes:
>
> >Dan Pop wrote:
> >>
> >> In <3AE43DEB...@adelaide.on.net> Mal Kay <malco...@adelaide.on.net> writes:
> >>
> >> >'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.
> >>
> >
> >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:

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

0 new messages