Names used for include guards?

前端 未结 3 1292
陌清茗
陌清茗 2021-01-22 15:25

Are there any guidelines people tend to follow when selecting a name for their include guard? I don\'t understand why the name for the .h file will slightly dif

3条回答
  •  感情败类
    2021-01-22 16:13

    To pick a good name for a header guard, consider these points:

    1) the name has to be unique, so make it long and specific. That can usually be accomplished by including things like project name, module name, file name and file extension.

    2) make sure you don't use names reserved for the implementation. So, names starting with underscore followed by a capital letter are out, as are names containing double underscore, names ending in _t and a few more.

    3) make the name make sense to human readers. So don't just generate a UUID and use that.

    4) convention dictates that you use all uppercase for macros to distinguish them from ordinary variables.

    Underscores are not needed, as such, but since you cannot use spaces in macro names, underscores serve as a good alternative to keep things readable.

    So, IMHO, a good guard name for a file foo.h in a submodule bar inside project baz is: BAZ_BAR_FOO_H .

提交回复
热议问题