gpt4 book ai didi

c - #include 实际上做了什么?

转载 作者:太空狗 更新时间:2023-10-29 16:24:52 25 4
gpt4 key购买 nike

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

#include "hello.h";

瞧,hello.h 中的每个函数和变量都可以自动使用。

但它实际上做了什么?我浏览了编译器文档和教程并花了一些时间在网上搜索,但我对神奇的 #include 命令的唯一印象是它“复制粘贴”了 hello.h 的内容 而不是那一行。肯定不止于此。

最佳答案

从逻辑上讲,复制/粘贴正是所发生的事情。恐怕没有更多的了。不过,您不需要 ;

您的具体示例包含在规范6.10.2 源文件包含 部分第 3 段中:

A preprocessing directive of the form

# include "q-char-sequence" new-line

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

关于c - #include 实际上做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5735379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com