单头,其中包括其他头 [英] Single header which includes other headers

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

问题描述

最近,我遇到了管理标题的这种做法。找不到其互联网上的问题很多信息,于是决定在这里问。

Recently, I encountered such approach of managing headers. Could not find much info on its problems on internet, so decided to ask here.

假设你有一个程序,你必须的main.c ,以及其他来源和标题,如: person.c,person.h, settings.c,settings.h,maindialog.c,maindialog.h,othersource.c,othersource.h

Imagine you have a program where you have main.c, and also other sources and headers like: person.c, person.h, settings.c, settings.h, maindialog.c, maindialog.h, othersource.c, othersource.h

有时 settings.c 可能需要 person.c 和主 maindialog.c

有时,一些其他的来源可能需要包括其他的源文件。
通常,人们会做内部的 settings.c

Sometimes some other source might need to include other source files. Typically one would do inside settings.c:

//settings.c
#include "person.h"
#include "maindialog.h"

不过,我遇到的做法,其中一个具有 global.h 和里面:

//global.h
//all headers we need
#include "person.h"
#include "maindialog.h"
#include "settings.h"
#include "otherdialog.h"

现在,从对方的源文件,你只需要包括global.h
和你做,你从各自的源文件获取功能。
请问这种做法与一个 global.h 头有一些真正的问题?

Now, from each other source file you only have to include "global.h" and you are done, you get functionality from respective source files. Does this approach with one global.h header has some real problems?

推荐答案

这是为了取悦既迂腐纯粹主义者和懒惰的极简主义。如果所有子报头做了正确的方式有通过 global.h 包括他们没有功能的危害,唯一可能的编译时间增加。

This is to please both pedantic purists and lazy minimalists. If all sub-headers are done the correct way there is no functional harm including them via global.h, only possible compile time increase.

副标题是有点像

#ifndef unique_token
#define unique_token
#pragma once

// the useful payload

#endif

这篇关于单头,其中包括其他头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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