c++cc-preprocessorheader-filesinclude-guards

What is the recommended naming convention for include guards?


How are include guards typically named? I tend to see this a lot:

#ifndef FOO_H
#define FOO_H

// ...

#endif

However, I don't think that's very intuitive. Without seeing the file name it's difficult to tell what FOO_H is there for and what its name refers to.

What's considered best practice?


Solution

  • From my own experience, the convention is to name the inclusion guards after the header file containing them with the exception that the name is all in caps and the period is replaced with an underscore.

    So test.h becomes TEST_H.

    Real life examples of this include Qt Creator, which follows this convention when auto-generating class header files.