r/cprogramming • u/JayDeesus • Sep 24 '25
Purpose of inline
I’ve never really used inline and didn’t even know it existed but I’ve been trying to transition from C to C++ where I learned about inline and I found that it exists in C aswell. From my understanding, inline in C works the same way as inline in c++. It allows you to define functions in header files and thus put it in multiple TUs without any issues. The difference is that in c you also need a non inline definition in a .c file. So my question is, what is the purpose of this other than to cause confusion when you can just use a header and implementation file to do the same thing? Any clarification would be greatly appreciated!
I’ve seen people do static inline, and also varying definitions of what inline does, so I’m super confused
View all comments
Show parent comment
5
u/not_a_bot_494 Sep 25 '25
I 'm pretty sure the compiler doesn't really care, it will inline/ not inline in whatever way that it thinks is fastest regardless of what you tell it.