DEV Community

Why Can't We Just #include "functions.c" in "main.c"? 🤔

EffessDev on November 26, 2026

Suppose we have two files. functions.c: #include <stdio.h> void greet(void) { printf("Hi!"); } main.c: int main(...
Collapse
 
nyaomaru profile image
nyaomaru Necoz •

I've mostly worked with languages that use imports, like TypeScript, Java, Python, and PHP, so learning how C handles separate compilation and linking was really refreshing! 😸

And congratulations on your first Necoz article! I love seeing members inspire each other to write new articles! 💚

Collapse
 
effessdev profile image
EffessDev Necoz •

🙀 Glad you learned something from me :)

Collapse
 
akhourianmolkumar profile image
Akhouri Anmol Kumar Necoz •

Collapse
 
johnclentoira profile image
john Clent Oira •

Really enjoyed this explanation! It's refreshing to see someone explain why C works this way rather than simply telling beginners to use header files and move on.
The distinction between compilation and linking is one of those fundamentals that becomes much more valuable as projects grow.
It also makes me wonder what you think about unity builds, where developers intentionally combine multiple source files to improve compilation performance. At what point do the benefits outweigh the drawbacks of separate compilation?

And writing this entire article on your phone during a bus commute? That's impressive. I can barely write a decent commit message on mine. 😂
Looking forward to more articles like this!

Collapse
 
effessdev profile image
EffessDev Necoz •

Thank you so much for the feedback! 😊 When I build an ESP-IDF project, the first compilation is very slow. But subsequent compilations are much faster. I think separate compilation is better during development, since we often update a few files and rebuild? 🤔

Collapse
 
akhourianmolkumar profile image
Akhouri Anmol Kumar Necoz •

I'm quite noob in mobile too.

Thread Thread
 
effessdev profile image
EffessDev Necoz •

Everybody's noob on mobile. Particularly on my mobile. Because it only has 4GB RAM. Apps automatically get cleared so there is no multitasking :( If I am writing an article and want to Google something, and I come back to write the article, the entire browser reloads 💀

I tried everything I know to fix this but no wayyy :(

Collapse
 
csm18 profile image
csm Necoz •

Absolutely awesome! You nailed a topic that many beginners struggle with. 🔥

Also, I'm really thankful to you for considering my post an inspiration! 😊

Collapse
 
effessdev profile image
EffessDev Necoz • • Edited

Hehe thanks! 🙂

Collapse
 
csm18 profile image
csm Necoz •

Absolutely!

Thread Thread
 
effessdev profile image
EffessDev Necoz •

Also, your post wasn't the inspiration. YOU were the inspiration (yeah, the post was also inspiration, but you were the first inspiration because the post came after I got inspired :))

Thread Thread
 
csm18 profile image
csm Necoz •

That means a lot to me man! Thank you 🧡

Thread Thread
 
effessdev profile image
EffessDev Necoz •

Thanks! 🙂

Collapse
 
technogamerz profile image
𝐓𝐡𝐞 𝐋𝐚𝐳𝐲 𝐆𝐢𝐫𝐥 Necoz •

I was waiting for this!

Collapse
 
effessdev profile image
EffessDev Necoz •

Thanks! I remember you telling me :)

Collapse
 
effessdev profile image
EffessDev Necoz •

Why @xulingfeng why? 😢

I'll write the next article for The Third Cup...

Collapse
 
xulingfeng profile image
xulingfeng Necoz •

😅

Collapse
 
the_daily_flare profile image
The daily flare •

I think the parallel compilation point finally made headers click for me.