Name: Anonymous 2015-09-07 22:21
struct your code correctly so you do not have headers inside headers
As a rough guide:
1. If a file which contains nothing but "#include <header.h>" fails to compile, that header is broken. If a header needs a declaration to be in scope (e.g. for the type of an argument in a prototype declared in that header), it's the header's responsibility to perform the include, not the file including the header.
2. If the order in which headers are included matters, one or more of the headers is broken.
3. If a header can't be included (directly or indirectly) more than once, it's broken.
There are some situations where these rules don't apply, but they're particularly rare (e.g. using the preprocessor as a ghetto template system).
FWIW, the only place in the C standard library where the rules don't apply is <assert.h>, because you're supposed to be able to enable and disable asserts with
As a rough guide:
1. If a file which contains nothing but "#include <header.h>" fails to compile, that header is broken. If a header needs a declaration to be in scope (e.g. for the type of an argument in a prototype declared in that header), it's the header's responsibility to perform the include, not the file including the header.
2. If the order in which headers are included matters, one or more of the headers is broken.
3. If a header can't be included (directly or indirectly) more than once, it's broken.
There are some situations where these rules don't apply, but they're particularly rare (e.g. using the preprocessor as a ghetto template system).
FWIW, the only place in the C standard library where the rules don't apply is <assert.h>, because you're supposed to be able to enable and disable asserts with
#undef NDEBUG
#include <assert.h>
// asserts enabled here
#define NDEBUG
#include <assert.h>
// asserts disabled here
#undef NDEBUG
#include <assert.h>
// asserts enabled here
// ... and so on