gpt4 book ai didi

c - 为什么我的讲师写的所有 C 文件的第一行都以一个 # 开头?

转载 作者:太空狗 更新时间:2023-10-29 16:13:32 28 4
gpt4 key购买 nike

我正在浏览一些 C 类(class)笔记,每个 C 程序源文件都在程序的第一行以单个 # 开头。

然后是空行,然后是 main 函数。

# 是什么原因?

(现在已经过期了,我真的不能问那个家伙。)

这是一个例子:

#

#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}

最佳答案

哇,这个要求可以追溯到 1970 年代。

在预标准化 C 的早期时代,如果您想调用预处理器,那么您必须编写一个#作为源文件第一行的第一件事。在文件顶部编写一个# 可以灵活地放置其他预处理器指令。

来自 an original C draft by the great Dennis Ritchie himself :

12. Compiler control lines

[...] In order to cause [the] preprocessor to be invoked, it is necessary that the veryfirst line of the program begin with #. Since null lines are ignored by the preprocessor, this line need contain no otherinformation.

该文档非常适合阅读(并让我像疯猫一样跳到这个问题上)。

我怀疑讲师只是多愁善感 - 自从 ANSI C 以来就不再需要了。

关于c - 为什么我的讲师写的所有 C 文件的第一行都以一个 # 开头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45629176/

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