best-practice on C header files with #ifndef #define #endif

后端 未结 5 2181
误落风尘
误落风尘 2020-12-09 18:25

what is concerned best practice regarding the following \"pattern\"?

#ifndef BLAFOO_H
#define BLAFOO_H
/* ...
 * ...
 */
#endif /* BLAFOO_H */
5条回答
  •  情书的邮戳
    2020-12-09 19:11

    The only real requirement is that it won't conflict with another project that uses the same name for its file. For all of the projects I've seen, it usually completely quantifies the namespace (or whatever folder the file is in for C) along with the project name. Sometimes it includes the date the file was created too.

    So if you're working on project ABC in folder DEF today, then you could do:

    #ifndef ABC_DEF_BLAFOO_H_05_30_2010
    

    And this is very unlikely to conflict with anything.

提交回复
热议问题