Just use pragma once
in all headers file. The compiler will ensure your file will be included only once. The compiler may only fail to recognize in very unreasonable condition: someone structure its include directories using hard-link. Who does this? If someone cannot find a unique name for its file, why would he be more skilled to find a unique name for each include guard for all the header files?
On the other hand, include guard may be broken because the name of the macro will not be that unique, because of a copy/paste, or a header file created by first copying an other, etc...
How are chosen the unique macro name: <project name>_<filename>
? How could it be more unique than a uniqueness based on the entire root directory structure?
So in the end, one should consider when choosing between include guard or pragma once
, the cost of the job that is necessary to ensure uniqueness:
1 - For pragma once
you only have to ensure that the directory structured of your system is not messed-out thanks to hard links.
2 - For include guard for each file on your system you should ensure that the macro name is unique.
I mean as a manager, evaluating the cost of this job and the failure risk does let only one option. Include guard are used only when no evaluation is performed: it is a non decision.
myclass.tpp
is supposed to be included only inmyclass.hpp
then it would make sense to add additional guards. – Sitzmark#error
directive if thehpp
guard is not defined. Just to offer a little protection from people including thetpp
first. – Foreboding.tpp
be included by others? if not (I guess), why guard over it? – Notarize.tpp
s (by user), then the guard is needed (but I'd say it'd be better to use.hpp
) – Notarize.tpp
, just like.cpp
– Notarize#pragma once
now that it is widely supported. – Pharmacist#pragma once
in every way. There's no reason to put the non-standard version in new code. – Pigeonhole