# C: warning: implicit declaration of function 'foo' [-Wimplicit-function-declaration]

**Code:** `implicit declaration of function` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

In C you called a function the compiler has not seen declared — usually a missing `#include`. Newer compilers treat it as an error.

## Meaning

Old C assumed an undeclared function returns `int` and accepts anything. That hides bugs such as truncated pointers on 64-bit systems. GCC 14 and Clang 16 turn it into a hard error, so old code that merely warned before may now fail to build.

## Common causes

- Missing `#include <stdlib.h>`, `<string.h>`, `<unistd.h>` or similar
- Calling a function defined later in the file without a prototype
- Misspelled function name
- Header not found because of a missing feature-test macro such as `_GNU_SOURCE`

## Quick fix

1. Include the header that declares it (see `man 3 name`)
2. Add a prototype above the first use
3. Compile with `-Wall -Werror=implicit-function-declaration`

## Detailed fix by platform

### GCC / Clang

1. `man 3 strdup` shows the header and feature macros
2. Add `#define _GNU_SOURCE` or `_POSIX_C_SOURCE 200809L` before the includes if the man page says so

## Code examples

### Declaring before use

```c
#include <stdlib.h>      /* declares malloc, free, atoi */
#include <string.h>      /* declares strlen, memcpy     */

int main(int argc, char** argv) {
    int n = argc > 1 ? atoi(argv[1]) : 0;   /* without stdlib.h: implicit declaration of function 'atoi' */
    return n;
}
```

## How to diagnose

1. **Name** — Spelling of the function?
2. **Header** — Which header does man say?
3. **Standard** — Is the file compiled as C99 or newer?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/implicit-declaration-of-function)
