r/C_Programming • u/Majestic-Instance704 • Jul 25 '26
why do header files contain only function declarations instead of full code body ? why have the code in a sepreate lib files ?
for context I am trying to learn gamedev on my own and setting up raylib/sfml confused me , then I learnt that the ( include )files only contained function declarations and the actual code was in( lib ) files (mind you but it is a weird name) , wouldn't it be more convenient to have them in the same file instead of linking ?
sorry if I sound stupid.
104
Upvotes
View all comments
Show parent comment
1
u/Conscious_Support176 Jul 26 '26 edited Jul 26 '26
C/C++ is pretty much the only language that does this?
#include is a pre-processor directive. It’s the wrong tool for the job, but it’s so deeply intertwined with how C is written that it’s hard to back out of it now.
Edit: yes, COBOL does something similar, and I’m sure some other “dinosaurs” might do too 🤔