为什么讲师编写的所有C文件在第一行都以单个#开头? [英] Why do all the C files written by my lecturer start with a single # on the first line?

查看:67
本文介绍了为什么讲师编写的所有C文件在第一行都以单个#开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一些C语言课程笔记,并且每个 C程序源文件都在文件第一行以一个开头。

I'm going through some C course notes, and every C program source file begins with a single # on the first line of the program.

然后有空白行,然后是其他内容,接着是 main 函数。

Then there are blank lines, and following that other stuff followed by the main function.

的原因是什么?

(这是

这里是一个例子:

#

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


推荐答案

哇,这个要求走了追溯到1970年代。

Wow, this requirement goes way back to the 1970s.

在预标准化C语言的很早天内,如果您想调用预处理器,那么您必须在源文件第一行中首先编写。在文件顶部只写 一个可以灵活地放置其他预处理程序指令。

In the very early days of pre-standardised C, if you wanted to invoke the preprocessor, then you had to write a # as the first thing in the first line of a source file. Writing only a # at the top of the file affords flexibility in the placement of the other preprocessor directives.

来自伟大的Dennis Ritchie自己的原始C草案


12。编译器控制行


[...]为了使预处理程序被调用,程序的第一行
必须以#开头。由于预处理器会忽略空行,因此该行不需要包含其他
信息。

12. Compiler control lines

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

该文档非常容易阅读(允许我

That document makes for great reading (and allowed me to jump on this question like a mad cat).

我怀疑这只是讲师多愁善感-自ANSI C以来就没必要了。

I suspect it's the lecturer simply being sentimental - it hasn't been required certainly since ANSI C.

这篇关于为什么讲师编写的所有C文件在第一行都以单个#开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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