Re:Results of the Grand C++ Error Explosion Competition
by ygra on Monday January 27, 2014 @04:17AM
(#7129481)
Hence include guards, yes. Agreed, I could have made that point a little better. Although they are usually only necessary when the header files contains things that may not appear twice in the same compilation unit, such as ... uhm, pretty much everything.
- foo.c includes bar.h and baz.h
- bar.h and baz.h both include qux.h
This is why most C header files have ifdef guards like this
#ifndef __BAR_H
#define __BAR_H
// contents go here
#endif
This makes sure that the contents of the header are only included the first time the preprocessor sees it in a particular file