是否冗余包括保护必要? [英] Are redundant include guards necessary?

查看:207
本文介绍了是否冗余包括保护必要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Codegear RAD Studio 2009中,冗余包含守卫是否必要?



例如,我可能在foo.h中有以下'include guard':

  #ifndef fooH 
#define fooH
// ...这里的声明
#endif

和use_foo.h中的以下'redundant include guard':

  #ifndef fooH 
#includefoo.h
#endif

此外,如果编译器不够聪明,冗余包括守卫,如果他们被包括在源文件中。例如 use_foo.cpp 。 ?

解决方案

标记为冗余包含警卫的代码部分不是必需的, 优化。



在C ++ Builder的情况下,有一个逻辑来检测头部保护,所以不需要。



在一般情况下,预处理通常通常相当快,所以这个优化不太可能会吸引你。 p>

Are 'redundant include guards' necessary in Codegear RAD Studio 2009? Is the compiler smart enough to deal with this on it's own?

For example, I might have the following 'include guard' in foo.h:

#ifndef fooH
#define fooH
// ... declaration here
#endif

and the following 'redundant include guard' in use_foo.h:

#ifndef fooH
    #include "foo.h"
#endif

Additionally, if the compiler is not smart enough, are 'redundant include guards' necesarry if they are being included in a source file. e.g. use_foo.cpp. ?

解决方案

The portion of the code you marked as "redundant include guard" is not necessary but it is a possible optimization.

In the case of C++Builder, there is logic to detect header guards, so it should not be necessary.

In the general case, the preprocessing pass is usually pretty fast anyhow, so it's unlikely that this optimisation would buy you much anyhow.

这篇关于是否冗余包括保护必要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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