Implicit Declaration of Function in C: How to Fix It

An implicit declaration of function diagnostic means the compiler encountered a function call before seeing a suitable declaration. Usually, you need to include the header that declares the function or declare your own function before calling it.
Do not suppress the message with a cast or with the removal of a warning; the compiler needs to know the function's actual types to check the call.
Fix a missing standard header
One of the most common examples is forgetting to type #include<stdio.h> before calling printf in your program. The following program includes the declaration before calling the function to fix this.
#include <stdio.h>
int main(void)
{
printf("Hello, C!\n");
return 0;
}
It prints Hello, C!. Don't forget to include the header file that is corresponding to the function you're using.
| Function | Header |
|---|---|
printf, puts, snprintf |
<stdio.h> |
malloc, calloc, free |
<stdlib.h> |
strlen, strcmp |
<string.h> |
sqrt, sin |
<math.h> |
isdigit, tolower |
<ctype.h> |
Including the header gives the compiler the declarations. Linking is a separate step and some libraries need an explicit linker option for your toolchain.
Declare your own function before using it
In this example, the function prototype appears before main, and the definition appears after it.
#include <stdio.h>
int double_value(int value);
int main(void)
{
printf("%d\n", double_value(6));
return 0;
}
int double_value(int value)
{
return value * 2;
}
Expected output:
12
The declaration and definition must agree. Here, we can move the function definition to before main; a definition is also a declaration.
For a multi-file project, put shared function declarations in a header and include it wherever those functions are called. Include it in the implementation file too, so the compiler can catch mismatched declarations. Do not include a .c file as a substitute for a proper build.
Why did old code compile before?
C99 and later do not support implicit function declarations. Some older compiler configurations accepted them as an extension or emitted a warning. GCC 14 changed several historical C diagnostics, including implicit function declarations, to errors by default in C99 and later modes. The correct solution is to provide the missing declaration, as the GCC 14 porting guide explains.
In C17, declare a function with no parameters as int get_value(void);. This is a declaration, not a definition with a body. The older spelling int get_value(); does not provide the same parameter information in C17.
What if the function is itoa?
itoa is not contained in the standard C library. Some toolchains have it, but adding <stdlib.h> does not make it portable. In order to format an integer as decimal text, use snprintf:
#include <stdio.h>
int main(void)
{
char text[32];
int written = snprintf(text, sizeof text, "%d", 12345);
if (written < 0 || (size_t)written >= sizeof text) {
fputs("Formatting failed or the buffer was too small.\n", stderr);
return 1;
}
puts(text);
return 0;
}
It prints 12345. The length check catches an encoding error or output truncation. This example is for decimal formatting and is not meant to be a replacement for all the itoa base options for every platform.
If the header is already included
Check the function's spelling and capitalization, then confirm that the header belongs to the library version you use. Platform-specific functions may require feature-test macros or may not exist on your operating system. Follow the library's documentation; inventing a prototype can hide an incompatible call.
Is this the same as an undefined reference?
No. An implicit declaration means the compiler cannot see the declaration at the call. An undefined reference means the linker cannot find a required definition. A project can have both problems, and each needs its own fix.
Run the corrected example in the online C compiler, then make the same header or declaration-order change in your program.