strings.h

T

Trying_Harder

Firstly, are functions defined in strings.h (`strcasecmp' and
`strncasecmp')
ANSI? if yes , then why am I getting an implicit declaration warning
only
with -Wall (Warnings all) flag? and if not, why am I not getting
warnings
with `gcc -ansi -pedantic blah.c'

Secondly , is there a function in `C' for comparing strings ignoring
their cases? Only criterion is this has to be ANSI compliant (being
precise, it
should compile without warnings with the following flags `-ansi
-pedantic &
-Wall' ).
After scouring through some newsgroup archives, I have got a hint
there isnt
any standard C function for this.
Conincidentally, I have always preferred using my own functions for
such
a logic and hence never encountered this problem before.


Thanks in advance,

f
 
G

Greg P.

| Firstly, are functions defined in strings.h (`strcasecmp' and
| `strncasecmp')
| ANSI? if yes , then why am I getting an implicit declaration warning
| only
| with -Wall (Warnings all) flag? and if not, why am I not getting
| warnings
| with `gcc -ansi -pedantic blah.c'

I guess because glibc isn't 100% perfect. Most implementations give some
warnings (when putting the warning flags up full-throttle).

| Secondly , is there a function in `C' for comparing strings ignoring
| their cases? Only criterion is this has to be ANSI compliant (being
<snip>

The only thing I can think of at the to of my head (at 4am) is to write a
function taking two const char* parameters, use temp char's and store
results from tolower() and check them one by one by iterating over each.
 
P

Phil Tregoning

(e-mail address removed) (Trying_Harder) wrote in
Firstly, are functions defined in strings.h (`strcasecmp' and
`strncasecmp') ANSI?

No. ANSI C does not require the functions 'strcasecmp' and
'strncasecmp' to be provided.
if yes , then why am I getting an implicit declaration
warning only with -Wall (Warnings all) flag? and if not,
why am I not getting warnings with `gcc -ansi -pedantic
blah.c'

All external identifiers starting with 'str' and a lower case
letter are reserved for use by the implementation. This means
that although the two functions are not required, a conforming
implementation is allowed to provide them.

As to why gcc does what it does, I can have a guess. It may
be because gcc is providing the functions, but no declarations
of them. In this situation, C89 does not require a diagnostic,
and because the functions return int and have char * arguments
(I assume) it is in fact required to work. However, an
implementation is allowed to give any diagnostics it likes,
hence the "implicit declaration warning" with -Wall.
Secondly , is there a function in `C' for comparing strings
ignoring their cases? Only criterion is this has to be ANSI
compliant (being precise, it should compile without warnings
with the following flags `-ansi -pedantic & -Wall' ).

The are no functions for case blind compares required by the
standard, but as I said, they are allowed.

Phil T
 
B

Ben Pfaff

Firstly, are functions defined in strings.h (`strcasecmp' and
`strncasecmp') ANSI? if yes , then why am I getting an implicit
declaration warning only with -Wall (Warnings all) flag? and if
not, why am I not getting warnings with `gcc -ansi -pedantic
blah.c'

No, ANSI says nothing about strings.h at all. The standard
without any `s'. Furthermore said:
Secondly , is there a function in `C' for comparing strings
ignoring their cases?

No. Actually, you could use strcoll() if you want a
locale-specific ordering, but that does more than just
case-insensitive comparison.
 
A

Alex

Ben Pfaff said:
(e-mail address removed) (Trying_Harder) writes:
No, ANSI says nothing about strings.h at all. The standard
string header is <string.h>, without any `s'. Furthermore, those
aren't standard functions.

Funny. I see at least one 's' in <string.h>. Or are you talking
about <tring.h>?

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top