织梦CMS - 轻松建站从此开始!

欧博ABG-会员注册-官网网址

欧博娱乐#include in .h or .c / .cpp?

时间:2025-12-01 05:06来源: 作者:admin 点击: 7 次
The only time you should include a header within another .h file is if you need to access a type definition in that header; for example: #ifndef MY_H

The only time you should include a header within another .h file is if you need to access a type definition in that header; for example:

#ifndef MY_HEADER_H #define MY_HEADER_H #include <stdio.h> void doStuffWith(FILE *f); // need the definition of FILE from stdio.h #endif

If header A depends on header B such as the example above, then header A should include header B directly. Do NOT try to order your includes in the .c file to satisfy dependencies (that is, including header B before header A); that is a big ol' pile of heartburn waiting to happen. I mean it. I've been in that movie several times, and it always ended with Tokyo in flames.

Yes, this can result in files being included multiple times, but if they have proper include guards set up to protect against multiple declaration/definition errors, then a few extra seconds of build time isn't worth worrying about. Trying to manage dependencies manually is a pain in the ass.

Of course, you shouldn't be including files where you don't need to.

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-12-04 23:12 最后登录:2025-12-04 23:12
栏目列表
推荐内容