Mail Archives: djgpp/1997/12/12/07:50:58
"John M. Aldrich" <fighteer AT cs DOT com> wrote:
> Ian Chapman wrote:
> >
> > Hi,
> > I tried to use the function strspn. I followed the example in libc.inf
> > and I got a warning implict declaration of function from the compiler.
> > The loader reported undefined ref. Is it in the libxxx.a?
Are you using C++? Are you including string.h? If the answer to these is
'yes' and 'no' respoctively, then that's the problem. The string functions
are all defined in string.h as C functions (i.e. with ordinary C external
names rater than the C++ mangled names). If you don't include the header
then the compiler will attempt to declare the function as
int strspn();
which when compiled with C++ will result in a 'mangled' name which won't
be found by the linker.
> I just ran a test program and examined the docs, and strspn() works
> fine. If you look closely at the example in the docs, there's a typo:
> strspn is misspelled as "strcspn".
Note that there are two functions. strspn returns the number of characters
at the start of the first string matching those in the second, and strcspn
returns the number not in the second. Or in other words, strspn returns the
index of the first character not in the second string and strcspn returns
the index of the first character in the second string.
So:
strspn ("abracadabra", "abc") == 2
strcspn("abracadabra", "cde") == 4
I hope (and believe) that the DJGPP library contains both, as per the ANSI
spec.
Chris C
- Raw text -