使用#ifndefine的基本问题 [英] Basic question on use of #ifndefine

查看:65
本文介绍了使用#ifndefine的基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要问一个非常基本的问题.任何人都可以在同一文件中解释这些语句的用法吗?这些语句一起书写意味着什么?

I need to ask a very basic question. Can anyone explain the use of these statements in the same file? What does these statements signify when written together?

#ifndef ABC_H
#define ABC_H
//code
#endif 

推荐答案

这称为包含防护.在C/C ++中,我们包含头文件.一个头文件可能包含在服务器的其他头文件中.假设您有两个这样的头文件,其中包括"File.h",则预处理器将File.h扩展两次.为了避免这种情况,我们使用了包含防护.

有关更多详细信息,请参见 [ ^ ]
This is known as inclusion guard. In C/C++ we include header files. It is possible that one header file may be included in server other header files. Suppose you have two such header files, which includes say "File.h", your preprocessor expands File.h twice. To avoid this we use inclusion guards.

For more details see this[^]


这些是包含防护".
请参见 http://en.wikipedia.org/wiki/Include_guard [
These are ''inclusion guards''.
See http://en.wikipedia.org/wiki/Include_guard[^]
Basically, they let you include the same header more than once in a module, without generating an error.

Hope this helps,

Pablo.


仅当未定义ABC_H时,才编译#ifndef ABC_H#endif之间的代码.

The code between #ifndef ABC_H and #endif is compiled only when ABC_H isn''t defined.

#define ABC_H行定义了ABC_H标识符.

经常使用此组合,以确保仅一次包含头文件.在编译器第一次进入文件时,没有定义ABC_H标识符,因此包含了文件的内容(并且定义了ABC_H标识符).下次编译器进入文件时,已经定义了ABC_H标识符...

This combination is used often, in order to ensure that a header file is included only one time. At the first time that the compiler enters to the file, the ABC_H identifier isn''t defined, so the content of the file is included (and the ABC_H identifier is defined). At the next time that the compiler enters to the file, the ABC_H identifier is already defined...


这篇关于使用#ifndefine的基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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