3 ms·
> I learned about how Plan 9 C code had non-traditional scheme of #include files where they don't put #ifdef wrappers in each .h file to allow multiple inclusio
by tpoacher 4y ago
> I learned about how Plan 9 C code had non-traditional scheme of #include files where they don't put #ifdef wrappers in each .h file to allow multiple inclusion and .h files don't include other .h files. As a result .c files have to include every .h file they need and in the right order. It's a bit of a pain and no other modern C++ codebase I know of maintains such discipline.
I've always thought this is exactly how headers should be treated. Effectively they should be interfaces importing functionality locally, and each header should make it explicit what is imported from name alone.
- mananaysiempre 4y agoThe problem with this scheme is that adding a dependency to a header now breaks source compatibility (even if nothing new needs to be linked in and a piece of a library just needs to pull in a different piece of itself or even of libc). It’s pretty and clean, but you need an environment that’s friendly to crosscutting changes to handle source-compat breakage. (Such as, yes, a dependency-tree leaf like an end-user application, or a monolithic tree like a traditional Unix.)
- kvnnews 4y agoYou can accomplish most of this by using forward declarations and the pimpl idiom as Scott Meyers recommends. Performance can be greatly improved with precompiled headers. Headers without pragmas or ifdef's sounds like masochism.