何时不使用包含头文件中的guard? [英] When not to use include guard in header file?
本文介绍了何时不使用包含头文件中的guard?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们都知道什么时候使用包括警卫,但是我们什么时候不能在我们的项目中使用它?
We all know when to use include guard, but when shall we not use it in our project?
GCC),有意地留下一个头文件(CUDA文件)而不包括保护。我只是好奇它。
Recently, I saw a project with mix compilation (CUDA + GCC), one header file (CUDA file) is deliberately left without include guard. I am just curious about it.
推荐答案
我的头顶有两种情况:
- 用于'x-macro'类型的功能,其中包含文件执行2部分的问题,例如定义一个枚举,然后定义一个对应于枚举的字符串名称数组
<
- when you want to turn on/off debugging capabilities (as how
assert.h
works) - for 'x-macro' type of functionality where you have the include file perform 2 parts of problem, such as defining an enum then defining an array of stringified names corresponding to the enums
这篇关于何时不使用包含头文件中的guard?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文