什么是真正的#include做? [英] What does #include actually do?

查看:163
本文介绍了什么是真正的#include做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C(或基于C语言),可以愉快地使用下面的语句:

In C (or a language based on C), one can happily use this statement:

#include "hello.h";

和瞧,每一个函数和变量 hello.h 是自动可用的。

And voila, every function and variable in hello.h is automagically usable.

但什么是它实际上做什么?我通过编译文档和教程看了看,花了一些时间在网上搜索,但唯一的IM pression我能形成与神奇的#include 命令它复制膏 hello.h 的内容,而不是该行。有一定有比这更多。

But what does it actually do? I looked through compiler docs and tutorials and spent some time searching online, but the only impression I could form about the magical #include command is that it "copy pastes" the contents of hello.h instead of that line. There's gotta be more than that.

推荐答案

逻辑上,复制/粘贴到底是什么情况。恐怕没有任何更给它。你并不需要在; ,虽然

Logically, that copy/paste is exactly what happens. I'm afraid there isn't any more to it. You don't need the ;, though.

您具体的例子是规范,部分覆盖的 6.10.2源文件包含,第3段:

Your specific example is covered by the spec, section 6.10.2 Source file inclusion, paragraph 3:

形式的preprocessing指令

A preprocessing directive of the form

#包括 Q-字符序列 新行

分隔符之间的指定序列标识的源文件的全部内容导致替代品,指令。

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters.

这篇关于什么是真正的#include做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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