![]() Otherwise, if a header included by this also includes header.h, then you end up with an infinite loop - not healthy. ![]() It is imperative, of course, to have the #define at the top of the file, not at the bottom. There's a standard idiom for that, too: #ifndef HEADER_H_INCLUDED Of course, this also requires you to ensure that headers are idempotent - work the same regardless of how often they are included. If it doesn't compile, fix things so that it does. If that compiles, the header is self-contained. The simple way to ensure this is to include the header in the implementation source - as the first header. That is, you should be able to write: #include "header.h"Īnd the code should compile correctly, with any other necessary headers included, regardless of what has gone before. One specific guideline, which I've adopted for my own code, is that headers should be self-contained. It has some good and interesting guidelines. Look at the Goddard Space Flight Center (NASA) C coding standard (at this URL).
0 Comments
Leave a Reply. |