Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Probably you should clarify what you mean in the top post. I still can't see anything but a dig on why single header libraries are wrong. Apologies if that's not the case.


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)


Minor 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


Thanks, you're certainly correct! I was a bit sloppy and didn't care to lookup the proper wording :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: