它是正确的,只是包括所有的头文件? [英] Is it right to simply include all header files?

查看:133
本文介绍了它是正确的,只是包括所有的头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

记住的系统头文件的名称是一种痛苦......

Remembering the names of system header files is a pain...

有没有一种方法,包括所有现有的头文件一次?

Is there a way to include all existing header files at once?

为什么没有人做呢?

推荐答案

包括不必要的头文件是一个极坏的做法。放缓编译可能或没有关系的问题;更大的问题是,它的隐藏依赖。您在源文件中包含头文件集的应该是一个什么样的功能模块依赖于文件,而不像外部文档或意见,它是由编译器自动检查的完整性(未包含所需的头文件将导致错误)。确保没有多余的依赖关系,不仅提高了便携性;它也可以帮助您跟踪不必要的和潜在危险的相互作用,例如情况下,这应该是纯粹的计算或纯粹的数据结构管理模块是访问文件系统。

Including unneeded header files is a very bad practice. The issue of slowing down compilation might or might not matter; the bigger issue is that it hides dependencies. The set of header files you include in a source file should is the documentation of what functionality the module depends upon, and unlike external documentation or comments, it is automatically checked for completeness by the compiler (failing to include needed header files will result in an error). Ensuring the absence of unwanted dependencies not only improves portability; it also helps you track down unneeded and potentially dangerous interactions, for instance cases where a module which should be purely computational or purely data structure management is accessing the filesystem.

这些原则适用的标题是你自己的程序或第三方库中的标准系统头或标头模块。

These principles apply whether the headers are standard system headers or headers for modules within your own program or third-party libraries.

这篇关于它是正确的,只是包括所有的头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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