Enclose the content of each header file in preprocessor guards:
/* a.h */
#ifndef A_H_
#define A_H_
/* content of a.h goes here */
#endif
Same for the other headers:
/* b.h */
#ifndef B_H_
#define B_H_
/* content of b.h goes here */
#endif
and so on.
That's the usual way to ensure that each header content is read only once. (When the file is read for the first time, the symbol [e.g. B_H_
] has not yet been defined, so ifndef
is true, and the content is read. From the second time on, the symbol is defined, and the content is skipped.)
Note that the name of the symbol A_H_
is arbitrary, but usually people use the name of the header written in capital letters. Hence the mechanism fails as soon as you include two different headers with the same name, unless you use different names for the guards.
You may also want to google for #pragma once
, which many preprocessors support, but which is not standard.