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/yuehuang Jul 26 '26
Most other languages that has binary distribution include the api functions in the binary itself. It is a small section of ascii text that the dll/so loader would ignore.
You can say that one for runtime and the other is for compile time. However, there are .lib and .a that is used only for compile/linker. These could be unified as into one format avoiding the header issue all together. This is the goal of the C++ Modules.