Why do all the C files written by my lecturer start with a single # on the first line?

后端 未结 3 1137
面向向阳花
面向向阳花 2020-12-22 14:52

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

3条回答
  •  太阳男子
    2020-12-22 15:27

    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.

提交回复
热议问题