No newline at end of file

后端 未结 12 2314

When doing a git diff it says \"No newline at end of file\".

Ok, there is no newline at end of file. What\'s the big deal?

What\'s the

12条回答
  •  被撕碎了的回忆
    2020-11-27 09:47

    Source files are often concatenated by tools (C, C++: header files, Javascript: bundlers). If you omit the newline character, you could introduce nasty bugs (where the last line of one source is concatenated with the first line of the next source file). Hopefully all the source code concat tools out there insert a newline between concatenated files anyway but that doesn't always seem to be the case.

    The crux of the issue is - in most languages, newlines have semantic meaning and end-of-file is not a language defined alternative for the newline character. So you ought to terminate every statement/expression with a newline character -- including the last one.

提交回复
热议问题