为什么不显式#include .c文件? [英] Why not explicitly #include .c files?

查看:52
本文介绍了为什么不显式#include .c文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C程序中,我看到.h文件始终使用以下方式明确包含:

In the C programs I've seen .h files are always explicitly included using:

#include "some_header_file.h"

另一方面,.c文件很少使用:

On the other hand .c files are very rarely included using:

#include "some_c_file.c"

三个问题:

  1. 为什么有区别?

  1. Why the difference?

您何时会偏离常规并明确包含.c文件?

When would you divert from the norm and include a .c file explicitly?

链接器如何知道项目中包含必需的.c文件以及在何处查找?

How does the linker know that a required .c file is included in the project and where to look for it?

推荐答案

为什么不同?

坚持模块化设计方法.

您何时会偏离常规并明确包含.c文件?

When would you divert from the norm and include a .c file explicitly?

大多数从不.

链接器如何知道项目中包含所需的.c文件以及在何处查找?

How does the linker know that a required .c file is included in the project and where to look for it?

链接器不需要.c文件,而需要编译器(在此问题中)从.c文件创建的.o文件(例如).这些.o文件所在的位置,链接程序由其调用方(IDE,makefile,用户)告知.

The linker does not need .c files, but .o files (for example) created by a compiler (in this question's context) from .c files. Where those .o files are located the linker is told by its caller (IDE, makefile, user).

这篇关于为什么不显式#include .c文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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