I am currently working on a big project and maintaining all those include guards makes me crazy! Writing it by hand is frustrating waste of time. Although many editors can generate include guards this doesn't help much:
Editor generates guard symbol based on a filename. The problem occurs when you have headers with the same filename in different directories. Both of them will get the same include guard. Including directory structure into the guard symbol would require some fancy approach from the editor, since slashes and backslashes in the macro are not the best thing.
When I have to rename a file I should rename all the include guards as well (in the ifndef, define and ideally endif's comment). Annoying.
Preprocessor is flooded with tons of symbols without a clue what they mean.
Nevertheless definition is included once, compiler still opens header every time it meets header inclusion.
Include guards don't fit into namespaces nor templates. In fact they are subverting namespaces!
You have a chance that your guard symbol won't be unique.
Maybe they were acceptable solution in times when programs contained less than 1000 headers in single directory. But nowadays? It is ancient, it has nothing to do with modern coding habits. What bothers me the most is that this issues could be almost compeletly solved by #pragma once directive. Why is it not a standard?
#pragma once
or another way to do the same thing. It is true that the filesystem is not under the control of the compiler, and that this can cause problems; but is this sufficient reason to decline to standardize a language/preprocessor feature so many programmers evidently find useful? Many useful language features can be abused, not only#pragma once
. Abuse of other useful language features is managed by compiler warnings and good programming practice. Is#pragma once
not likewise a feature of this kind? – Teenateenage