3 ms·
I think OP was quite clear. They didn't say that single header libraries are wrong per se, but that it's bad practice to not declare functions in headers as inl
by spacechild1 6y ago
I think OP was quite clear. They didn't say that single header libraries are wrong per se, but that it's bad practice to not declare functions in headers as inline, because it can cause accidental code duplication.
EDIT: I see now that this advice is only valid for C++, where the "inline" keyword creates a weak symbol. I forgot that this doesn't work in C.
Anyway, the #define trick is only necessary for C, in C++ you would simply declare all functions as "inline" (which automatically happens for function templates, btw)
- ludocode 6y agoMinor nitpick, but inline and weak are not the same thing. Weak linkage is a property that is resolved by the dynamic linker (at runtime startup); inline linkage is a property that is resolved by the static linker (at compile-time linking.) GCC calls inline "vague linkage" and it only uses weak linkage if the platform does not have COMDAT support: https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html
- spacechild1 6y agoThanks, you're certainly correct! I was a bit sloppy and didn't care to lookup the proper wording :-)