Why is it recommended to have empty line in the end of a source file?

后端 未结 8 900
独厮守ぢ
独厮守ぢ 2020-12-02 04:44

Some code style tools recommend this and I remember seeing some unix command line tools warning about missing empty line.

What is the reasoning for having an extra e

8条回答
  •  忘掉有多难
    2020-12-02 05:33

    The empty line in the end of file appears so that standard reading from the input stream will know when to terminate the read, usually returns EOF to indicate that you have reached the end. The majority of languages can handle the EOF marker. It is there for that reason from the old days, under DOS, the EOF marker was F6 key or Ctrl-Z, for *nix systems, it was Ctrl-D.

    Most, if not all, will actually read right up to the EOF marker so that the runtime library's function of reading from input will know when to stop reading any further. When you open the stream for Append mode, it will wipe the EOF marker and write past it, until a close is explicitly called in which it will insert the EOF marker at that point.

    Older tools were expecting a empty line followed by EOF marker. Nowadays, tools can handle the empty line and ignore it.

提交回复
热议问题