How are C++ include guards typically named? I tend to see this a lot:
#ifndef FOO_H
#define FOO_H
// ...
#endif
However, I don\'t think
As others mentioned before, a very common convention is to use the uppercase version of the name, and the dot replaced by an underscore: foo.h -> FOO_H
However, this can lead to name collisions with simple and/or common names. For this reason, autogenerated header like the stdafx.h in non-empty Visual C C++ projects append some random string, like:
#ifndef FOO_H__NsknZfLkajnTFBpHIhKS
#define FOO_H__NsknZfLkajnTFBpHIhKS
#endif
http://www.random.org/strings/ is a useful random generator for this.
Also, if the file is part of some submodule, or its contents reside in one specific namespace, I tend to add that to the guard too:
#ifndef SOMECOMPONENT_FOO_H__NsknZfLkajnTFBpHIhKS
#define SOMECOMPONENT_FOO_H__NsknZfLkajnTFBpHIhKS
namespace somecomponent
{
...
}
#endif
I normally use something like FOO_H_INCLUDED_
. A few (Microsoft) headers have what looks a lot like a string representation of a GUID, but I've never needed anything quite that elaborate.
I personally follow Boost's recommendation. It's perhaps one of the largest collection of C++ libraries of good quality around and they don't have problem.
It goes like:
<project>_<path_part1>_..._<path_partN>_<file>_<extension>_INCLUDED
// include/pet/project/file.hpp
#ifndef PET_PROJECT_FILE_HPP_INCLUDED
which is:
_[A-Z]
or containing __
is not)INCLUDED
you're spoiling for a fight)I've read about GUID but those look weird.
And obviously I'd rather than all compilers implement #pragma once
(or better, #pragma multiple
and "once" be the default behavior...)