I tried compiling with or without the inclusion guards in C headers and made sure that multiple c files includes the same header. It would result to redeclaration and it is allowed. What does it for then?
Asked
Active
Viewed 67 times
1 Answers
3
You prevent circular inclusion:
Example
/** file A.h */
#include "B.h"
/** file B.h */
#include "A.h"
What will happen if you include either "A.h" or "B.h"? Your pre-processor will try to include the other file, which will include the other file, which will include the other file, …
Guards make sure that you won't include the file several times.

Zeta
- 103,620
- 13
- 194
- 236
-
Would it cause a compiler error if that's the case? Because I just tried it in dev cpp and it still did compile. – Xegara Nov 10 '13 at 16:38