eclipse的自动生成的.h文件防护 [英] eclipse's auto-generated .h file guards
问题描述
在eclipse中,创建c ++类后,.h文件会自动生成带有保护 XXXX_H _
的文件。以我有限的,很少的经验,后卫总是以 XXXX_H
的形式出现,而没有结尾的 _
。
In eclipse, when a c++ class is created, .h file's auto-generated with guard XXXX_H_
. In my limited, little experience, the guard is always be in the form of XXXX_H
without the trailing _
.
所以,我很好奇,想知道为什么 _
在那儿。
So, I'm just curious and wondering why the _
is over there.
谢谢。
推荐答案
结尾的 _ $ c $可以添加c>以避免与用户定义的标识符冲突。例如,您可能有一个名为
。因此,在 get.h
的头文件,并且同时可以想象有一个名为<$ c $的宏(或变量或函数)。 c> GET_H get.h
中使用 GET_H
作为包含保护很容易导致问题。
The trailing _
might be added to avoid collision with user-defined identifiers. For example, you might have a header file named get.h
and at the same time you can conceivably have your own macro (or variable, or function) named GET_H
. So, using GET_H
for include guard in get.h
would easily lead to problems.
出于相同的目的,标准库头文件可能会使用前导 _
为其内部宏命名-避免名称与用户定义冲突身份标识。因此,语言规范明确禁止以 _
和大写字母开头的用户定义标识符。出于同样的原因,前导 _
不能用于包含防护的名称。
The standard library header files might use a leading _
to name its internal macros for the very same purpose - to avoid name collision with user-defined identifiers. For that reason, the language specification explicitly prohibits user-defined identifiers that begin with _
and a capital letter. And for the very same reason, the leading _
cannot be used in the names of include guards.
因此,Eclipse出于相同的目的决定使用跟踪 _
。它提供了合理的保护级别,以防止名称冲突,并且不违反语言规范的要求。
So, Eclipse decided to use a trailing _
for the very same purpose. It provides a reasonable level of protection from name collisions and does not violate the requirements of language specification.
这篇关于eclipse的自动生成的.h文件防护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!