larry*wei 2017-08-11 07:17 采纳率: 0%
浏览 238
已采纳

为什么我的讲师写的所有 c 文件都以 # 开头?

Why do all the C files written by my lecturer start with a #?

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.

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

What is the reason for the #?

(It's out of term now and I can't really ask the chap.)

Here's an example (there is an extra line at the end of the closing })

#

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

转载于:https://stackoverflow.com/questions/45629176/why-do-all-the-c-files-written-by-my-lecturer-start-with-a

  • 写回答

1条回答 默认 最新

  • Memor.の 2017-08-11 07:19
    关注

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

    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.

    From 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 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).

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号