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

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

问题描述

关于以下模式"的最佳实践是什么?

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

#ifndef BLAFOO_H
#define BLAFOO_H
/* ...
 * ...
 */
#endif /* BLAFOO_H */

我应该如何在 #define 指令中命名标题?我已经看到了从 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(我个人使用 BLAFOO_H_ 其中 BLAFOO 是头文件名).

Name them BLAFOO_H (personnally I use BLAFOO_H_ where BLAFOO is the header file name ).

确保您的 BLAFOO 不会与其他文件/库/等发生冲突.你正在使用,例如让您的项目和/或模块名称成为该名称的一部分.

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天全站免登陆