与的#ifndef的#define #ENDIF C头文件的最佳实践 [英] best-practice on C header files with #ifndef #define #endif
问题描述
什么而言就以下模式的最佳做法?
what is concerned best practice regarding the following "pattern"?
#ifndef BLAFOO_H
#define BLAFOO_H
/* ...
* ...
*/
#endif /* BLAFOO_H */
我应该如何命名在的#define
指令的头?我见过的所有从该<code> BLAFOO_H 到 __ BLAFOO_H
到 _BLAFOO_H _
等
how should i name the header in the #define
directive? i've seen all from said BLAFOO_H
to __BLAFOO_H
to _BLAFOO_H_
etc..
推荐答案
将它们命名为 BLAFOO_H
(personnally我用 BLAFOO_H _
其中BLAFOO是头文件名)。
Name them BLAFOO_H
(personnally I use BLAFOO_H_
where BLAFOO is the header file name ).
请确保您的BLAFOO不与其他文件/库/等发生冲突。您正在使用,例如有你的项目和/或模块名称是名PARTH。
Make sure your BLAFOO doesn't clash with other files/libraries/etc. you're using, e.g. have your project and/or module name be parth of that name.
开始以标识符_
是保留给执行/编译器,所以不要使用。
Identifiers starting with a _
is reserved for the implementation/compiler, so don't use that.
这篇关于与的#ifndef的#define #ENDIF C头文件的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!