3 ms·
Header only c libs also emerge from c and c++ realities that are less true elsewhere. The biggest one is the optimizer does a better job when stuff is in the s
by asveikau 7y ago
Header only c libs also emerge from c and c++ realities that are less true elsewhere.
The biggest one is the optimizer does a better job when stuff is in the same compilation unit. (Inlining and stuff.) A good example to look at is sqlite, which is developed as multiple files but they concatenate them together for distribution.
Another reason is a C++ one, and C is not C++ but the community has enough overlap that I think it tends to spill over. And that is templates. Templates need to be in the header so a lot of c++ libraries have complicated, slow to compile headers.
I do think, for example when any given person on HN links to a header only C or C++ library, that a lot of these people are overdoing it. They have likely not measured it and found it to be better like the sqlite people. They are fighting, perhaps even misunderstanding the tooling, at the cost of compile times and large binary sizes. And for what? Makefiles are not really that hard to write.