2 ms·
> the inline keyword is also available in C (since C99) but it doesn't work the same way. > If you put all the implementation code into inline code, this code
by spacechild1 6y ago
> the inline keyword is also available in C (since C99)
but it doesn't work the same way.
> If you put all the implementation code into inline code, this code is parsed over and over again in each source file
That's true. Good header-only C++ libraries provide "forward" headers, which you can use if you don't need the full definition.
But the best thing is to only write C++ header-only libraries if there is a technical reason (e.g. heavy templated code).
> "STB-style single file libraries" don't suffer from this problem.
That's right, but I also don't see the benefit. To me, telling the user to add a #define to some random source file feels incredibly hacky. On a technical level, it's the same as asking the user to #include a ".c" file.
Why not put the implementation in a single ".c" file, which the user can add to their project? I honestly don't understand this...