Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: implicit declaration of function

Tags:

c

I'm programming in C and my gcc compiler gives me the following warning in my function call in mySedondFile.c:

implicit declaration of function 'func'

The function prototype is declared in myfile.h as:

void  func(char*);

Function definition is in myfile.c

void  func(char*x);

mySecondFile.c contains:

#include "myfile.h"

func("Hello");

I'm missing why this would complain.

like image 679
SSS Avatar asked Jan 30 '26 13:01

SSS


1 Answers

That error is emitted because func has not been declared at the point at which you call it.

It sounds like your header files aren't quite as you describe. Perhaps there is some conditional code. Maybe you have a header guard that is not working right. Another possibility is that you have got a letter case error and declared the function Func but called it with func. Very hard to say without seeing the actual files but you need to look for a reason why func is not declared in the mySecondFile.c translation unit.

To illustrate this a little more clearly, the following code:

int main(void)
{
    func("Hello");
    return 0;
}

results in this warning:

prog.c: In function ‘main’:
prog.c:3: warning: implicit declaration of function ‘func’

which is exactly as you report.

According to your description, your code includes a header file which declares func. The compiler begs to differ with you and it remains for you to work out why func is not declared.

like image 85
David Heffernan Avatar answered Feb 01 '26 04:02

David Heffernan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!