Implicit declaration of function

in short, warning: implicit declaration of function means that the compiler didn’t find the function prototype declaration of the function which you are trying to call

in reality, why the compiler is giving you a warning, not an error

because the compiler didn’t find the function prototype declaration but it found the function declaration and that is enough for a C compiler to compile the code

here implicit(inside) means the compiler will create an implicit declaration for you and assume the return type of that function to be an int and compile the code

in case, if you declare the return type of a function declaration as a float or any other data type except int will cause an error called conflicting types

until now, clear as mud?

in reality, it is the job of the compiler to match the types of arguments that you pass in a function call are the same in the function prototype declaration

if any mismatch happens then the compiler will throw a warning in C but, on the other hand, it will create an error in C++

But, why warning in C and error in C++

because C is a loose typecast language that allows implicit conversions whereas C++ is a strong typecast language that requires explicit conversions

lets deconstruct some examples

#include <stdio.h>
void myFunction();//function prototype declaration

int main() {
  myFunction(); // function call
  return 0;
}
// Create a function called myFunction
void myFunction()//function declaration
 {
  printf("I just got executed!");
}

to clarify, here, in the above example, the function call myFunction() should match with the function prototype declaration void myFunction();

like it or not, if the compiler didn’t find the function prototype declaration for which the function call is made then in that case it throws a warning such as an implicit declaration of function

so far, okay,

Here’s another one

as a matter of fact, in C to use built-in functions, you need to #include<filename.h>

Here’s an example

in general, to use built-in functions of mathematical functions<math.h> such as

Sin(x)

Cos(x)

Pow(x,y) ………… …………so on

not to mention, you should #include<math.h> at the top section of the code

But, Why?

In essence, the math.h file contains a collection of function prototype declarations for math functions

that is to say, if you don’t include math.h file at the top of the code

undoubtedly, your function calls will not be discovered by the compiler

but why?

Because your function call doesn’t match the function prototype declaration  that a header file math.h have

as I have said, the function call that you have created will not get match the function prototype declaration by the compiler

as a result, a warning: implicit declaration of function will be issued

In C, if you didn’t include the math.h file to access the math functions then, at that instant,  a warning will be issued but the code can be executed

But this is not possible in C++ if you didn’t include math.h file at the top of the code   to access math functions, then, in that case, the compiler will throw an error not a warning

But Why?

Because C++ is a strong typecast language

Mohammed Anees

Hey there, welcome to aneescraftsmanship I am Mohammed Anees an independent developer/blogger. I like to share and discuss the craft with others plus the things which I have learned because I believe that through discussion and sharing a new world opens up

Leave a Reply

Your email address will not be published.