I came across such piece of code:
a.h:
#include "b.h"
/* structure definitions, macros etc. */
b.h:
#include "a.h"
/* structure definitions, macros etc. */
Is this legal from the C standard point of view? I would think such approach isn't safe.
You need to use include guards. Then it will be safe.
a.h
#ifndef A_H
#define A_H
/* ... */
#endif
It is legal. All compilers that I know of impose a nesting limit, usually in the range of 20 to 50. Recursion, if useful, is easily controlled with condtionals:
#if NESTING < 5
#define NESTING NESTING+1
#include "myself.h"
#endif
There are thousands of ways to shoot yourself in the foot as a programmer. This is just one more way. Be careful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With