<p>How does one prevent an inclusion cycle in C? ie. You shouldn't have a.h #include "b.h", which #include's "c.h" which #include's "a.h". I'm looking for a way of preventing this from happening using some sort of C directive.</p>

<p>I had originally thought this would've prevented this from happening:</p>

<p>Contents of a.h:</p>

<pre><code>#ifndef __A_H
#define __A_H

#include "b.h"

#endif // __A_H
</code></pre>

<p>Contents of b.h:</p>

<pre><code>#ifndef __B_H
#define __B_H

#include "c.h"

#endif // __B_H
</code></pre>

<p>Contents of c.h:</p>

<pre><code>#ifndef __C_H
#define __C_H

#include "a.h"

#endif // __C_H
</code></pre>

<p>But it doesn't seem to work.</p>

It does work allright: the files
are
repeatedly included, but the sections protected by #ifdndef/#define/#endif
are not
repeated, and that breaks the cycle.
Use your compiler to produce the preprocessed output and look at it for yourself.  With GNU CC, you need to use "-E" option on the .c[pp] file, like this:
```
```
gcc -E $(CFLAGS) -o foo.i foo.cpp
```
```