与的#ifndef的#define #ENDIF C头文件的最佳实践 [英] best-practice on C header files with #ifndef #define #endif

查看:142
本文介绍了与的#ifndef的#define #ENDIF C头文件的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么而言就以下模式的最佳做法?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆