它是把所有的包含一个头文件是一个好主意? [英] Is it a good idea to put all of your includes in one header file?

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

问题描述

什么是C中的最佳实践是什么,你把C头文件?

What is the best practice for C what you put into a C header file?

是不是把所有的包括用于多个源文件的程序在一个头文件有用吗?

Is it useful to put all the includes used for a program across multiple source files in one header file?

怎么样包括在几乎每一个文件中使用(即stdio.h中)?

What about includes that are used in practically every file (i.e. stdio.h)?

推荐答案

没有。它只是增加了克鲁夫特和开销。

No. It simply adds cruft and overhead.

一个作为维护者搞清楚什么头的不,你将面临的最大的烦恼的需要包含并摆脱他们。 WHE你得到20+标题的列表,你开始考虑丑陋的东西的了野蛮通过它强迫(在删除一个一时间,如果有任何中断看到)。

One of the biggest pains that you'll face as a maintainer is figuring out what headers don't need to be included and get rid of them. Whe you get to a list of 20+ headers, you start contemplating ugly things like brute forcing through it (removing one at a time and seeing if anything breaks).

善待谁必须保持你的东西在未来的人。使用你每个模块所需要的头文件,没有更多的..没有少:)

Be kind to people who have to maintain your stuff in the future. Use the headers you need per module, no more .. no less :)

这篇关于它是把所有的包含一个头文件是一个好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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