LoginSignup
1
2

GitHubとかで最終行に改行がないと警告が出る訳

Posted at

GitHubにコードを上げたときにこのような絵文字を見かけたことがある人は何人かいるはず。

image.png

これは「最終行に改行がない」という警告で、JetbrainsのIDEなどではそもそもファイル作成時に末尾改行を自動的に挿入している場合も多い。

なぜ警告がでるのか

これはPOSIXとC言語の標準ルールが原点で、POSIXにおけるファイルの中の行の定義で、

A sequence of zero or more non- <newline> characters plus a terminating <newline> character.

「0個以上の改行以外の文字と終端に一つの改行文字」が一行の定義で、これからなるC言語の標準として

A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character.
Since this is a "shall" clause, we must emit a diagnostic message for a violation of this rule.

「空でないソースファイルは改行で終了しなければならない」というふうに定められたのが、現代においてコーディング規約に残っていると考えられる。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2