Why Can't We Just #include "functions.c" in "main.c"? 🤔
Post · https://dev.to/necoz/why-cant-we-just-include-functionsc-in-mainc-1a73
Suppose we have two files. functions.c: #include <stdio.h> void greet(void) { ...
First seen by Oriel on .
AI summary
The article explains why C projects use header declarations and compile implementation files separately instead of including a `.c` file directly.
- `#include` copies a file's contents into the source before compilation, so a header can provide `void greet(void);` without including its implementation.
- Each source file is compiled separately into an object file; the linker later resolves calls to functions defined in other files.
- Function declarations tell the compiler a function's name, parameter types, and return type so it can compile a call in another translation unit.
- Including `functions.c` would combine sources into one compilation unit, prevent reuse of unchanged object files, and risk duplicate definitions when included by multiple files.
- `#pragma once` only prevents repeated inclusion within one compilation unit; it does not prevent duplicate definitions across separately compiled files.
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Reactions
Total public reactions reported by the source; distinct from points and likes.
- DEV Community: 57, latest observation ; +1 over observed period since
Comments
Comment count reported by the source.
- DEV Community: 102, latest observation ; +7 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| DEV Community | 5113714 | https://dev.to/necoz/why-cant-we-just-include-functionsc-in-mainc-1a73 Read discussion |