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 Aug 02 '26 edited Aug 02 '26
You literally asked me for an example, and I gave you numerous examples. What you are talking about is ABI stability across compiler versions. The point there isn’t about shared libraries as much it is about shared libraries in the context of a compiler that is still evolving and may decide to break the binary ABI. If you ensure you are using compilers that compile to the same ABI then you don’t need to specify the extern linkage. Even then, you don’t need a header file for rust.
What you need a header file for is, C calling rust. Because C doesn’t know anything about rust modules and cannot extract the information it needs from them, and in fact there is no way to provide it with a rust adaptor because include files are the one and only way that the C compiler can learn this information about other libraries.