5 ms·
Love to see stuff like this. I wonder why he put all of the code in a header file, though... I've never seen that done before; it seems like it would make it i
by commandlinefan 7y ago
Love to see stuff like this. I wonder why he put all of the code in a header file, though... I've never seen that done before; it seems like it would make it impossible to invoke this from two separate source files?
- mmozeiko 7y agoHere's a rationale for this from an author of very popular many single-header libraries: https://github.com/nothings/stb#why-single-file-headers https://github.com/nothings/stb#why-single-file-headers As to how to use from two separate translation units - you need to define PL_MPEG_IMPLEMENTATION to actually include implementation. So you do that in one of your .c files. Rest of includes will have only declarations included.
- zzo38computer 7y agoI like it too, to have just one file rather than many large and complicated files. Some programs I have seen do put everything in the header file, although I prefer to have a separate header file and program file, although having only the header file still works too. It isn't impossible to invoke from two separate source files, because there is a macro that you can define to specify if you want to include the implementation or not.
- newnewpdro 7y agoIt's somewhat trendy these days, but the main reason I've found is windows developers struggle with adding third-party dependencies to their projects because their development environment sucks.
- kevin_thibedeau 7y agoI think it's mostly game devs backporting C++ flaws into C.
- Impossible 7y agoAlthough this is getting downvoted because it is somewhat inflammatory (stops just short of using "winblowz" and "M$"), there is some truth to it. Visual Studio does have a package manager but its not widely used, and in practice can't be used in a lot of environments that C\C++ Windows developers (often game developers) are using. That said, I've seen stb_image used widely in environments that are not Windows because even if you have package manager and a build system that manages dependencies better than vanilla MSBuild it's still lower friction to include a single header file library. Last time I used xcode, dependency management was about as painful as visual studio but I might have been doing it wrong.
- blondin 7y agosingle headers (take it from a non c/c++ expert here just observing): 1. speeds up compilation -- through a single compilation unit. which as far as i understand is making the compiler compile a single "huge" pile of code. and because computers are extremely fast, is faster than figuring out dependencies using a build tool 2. makes dependency management easier (no make, no cmake, no scons, no ninja, etc.) 3. makes customization easier (just drop a macro and you can include just want you need) i love the idea and empathize with the need for it.