|
The only time you should include a header within another .h file is if you need to access a type definition in that header; for example: #ifndef MY_HEADER_H #define MY_HEADER_H #include <stdio.h> void doStuffWith(FILE *f); // need the definition of FILE from stdio.h #endifIf header A depends on header B such as the example above, then header A should include header B directly. Do NOT try to order your includes in the .c file to satisfy dependencies (that is, including header B before header A); that is a big ol' pile of heartburn waiting to happen. I mean it. I've been in that movie several times, and it always ended with Tokyo in flames. Yes, this can result in files being included multiple times, but if they have proper include guards set up to protect against multiple declaration/definition errors, then a few extra seconds of build time isn't worth worrying about. Trying to manage dependencies manually is a pain in the ass. Of course, you shouldn't be including files where you don't need to. (责任编辑:) |
