Naming Include Guards

前端 未结 9 1236
忘了有多久
忘了有多久 2020-11-29 08:37

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

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 08:58

    Taken directly from google's style guide:

    All header files should have #define guards to prevent multiple inclusion. The format of the symbol name should be ___H_. To guarantee uniqueness, they should be based on the full path in a project's source tree. For example, the file foo/src/bar/baz.h in project foo should have the following guard:

     #ifndef FOO_BAR_BAZ_H_
     #define FOO_BAR_BAZ_H_
     ...
     #endif  // FOO_BAR_BAZ_H_
    

    I use this style in my own projects.

提交回复
热议问题