Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

warning: implicit declaration of function 'strcmp'? 2

Status
Not open for further replies.

mattias1975

Programmer
Jul 26, 2004
36
SE
Hello!

I get an irritating warning from the compiler:

myapp.c: 166: warning: implicit declaration of function 'strcmp'

Line 166 looks like this:

if(strcmp(listpointer->name, search->name)==0){

......
}

listpointer->name and search->name are char[100].

Whats the compiler complaining about?
How do i fix it?
I get the same warning when i call the strcpy function on another line in my code.

Thank you.


 
It means you missed

Code:
#include <string.h>



--
 
It's complaining because, in C, if you don't declare a function (or include a header file that does so for you), then you try to use that function, the compiler goes ahead and declares it as having a return type of int. That's the implicit declaration.

The "preferred" behavior (i.e. if they could go back in time and write C all over again) would be to just give an error about implicit declarations. However, too much old code depends on this behavior, so you're stuck with the warnings.


As a side note, that's why you'll see a lot of sources telling you to never write something like:
Code:
#include <stdio.h>

int main() {
    char* ch = (char*)malloc(20);
    printf("Hi\n");
    free(ch);
    return 0;
}
Note stdio.h was "forgotten." If you didn't have the cast there, the compiler would implicitly declare malloc (with an int return type instead of a void* like it's supposed to), and the cast would keep the compiler from complaining about the fact that you're making a strange conversion, so it might compile without any warnings. This could lead to subtle bugs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top