理念解决隐含包括C,C ++ [英] Idea for resolving implicit includes in C, C++

查看:124
本文介绍了理念解决隐含包括C,C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚想出了一个主意来解决问题,并希望分享。很抱歉,如果过于平庸。

I've just came up with an idea to solve a problem and wanted to share it. Sorry if too banal.

所以,一个大的C ++项目我检讨,包含了许多包括依赖于符号从其他包括,但不包括所需要的包括。在集结过程结果的任何细微变化,失踪符号的失败。

So, a big C++ project I am reviewing, contains many includes which relies on symbols from other includes but which don't include the required includes. Any slight change in build-procedure results in "missing symbol" failures.

因此​​,为了检查所有包括自我遏制一次,我搜索所有的* .h,创建于飞CPP文件只包含的#include语句来此的.h文件,并尝试编译。最后我得到的好与坏包含文件的列表。
酷派是不是:-)
还是有更简单的解决方案呢?

So in order to check all includes for self-containment at once, I search for all *.h, create on the fly a cpp-file which only contains #include -statement with this .h file and try to compile it. At the end I obtain a list of "good" and "bad" include files. Cool isn't it :-) Or is there an easier solution to do it?

推荐答案

如果每个.cpp文件包括它首先是自己的头文件,然后其他的标题,你会得到这张支票,而无需使用外部工具。

If every .cpp file includes it's own header-file first, and then other headers, you'll get this check without using external tools.

这其实是 Google的C ++风格指南<的一部分/ A>出于同样的原因:

This is actually part of Googles C++ Style Guide for the same reason:

在preferred订货减少隐患
  依赖。我们希望每个头
  文件被独立编译。该
  实现这一目标最简单的方法是使
  确保他们每个人是
  第一.h文件中包含(#include)在某些.CC。

The preferred ordering reduces hidden dependencies. We want every header file to be compilable on its own. The easiest way to achieve this is to make sure that every one of them is the first .h file #included in some .cc.

如果您有没有相应的.cpp文件的头文件,你必须做一些特别的他们。

If you have any header files that does not have a corresponding .cpp-file, you'd have to do something special for them.

这篇关于理念解决隐含包括C,C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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