6

Possible Duplicate:
“No newline at end of file” compiler warning

i am a Linux user and use gcc at work But at home i have installed cygwin package and using its gcc on my windows machine.

when ever i make any .c file and run its shows following warning

Warning : No new line at end of file 

when i add extra new line at the end of that c file warning disappeared. i haven't faced such warning while working with gcc in Linux.

so

why i am getting this warning? what does it mean ?

Edit

Whats the need or whats the advantage of doing this ?

if it is part of c programming standard then why it doesnt give any error while working in linux ?

Community
  • 1
  • 1
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
  • 2
    See also http://stackoverflow.com/questions/72271/no-newline-at-end-of-file-compiler-warning (that question is about C++). – interjay Nov 17 '11 at 18:23
  • 3
    Well it means that there is no new line at the end of the file... – K-ballo Nov 17 '11 at 18:23
  • after my edit it not duplicate with that question – Jeegar Patel Nov 17 '11 at 18:28
  • 1
    Why it is a good habit to leave a line at the EOF is when you include header files say the statement was #include "header.h"extern int a; This could lead to errors as tokens will get tangled. – Ram Nov 18 '11 at 09:37

2 Answers2

16

The C language requires that every source file must end with a newline (from C99 5.1.1.2/1):

A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place.

(C++ also had this requirement prior to C++11)

James McNellis
  • 348,265
  • 75
  • 913
  • 977
1

No newline at end of file shows why you are getting this error and why it may be bad not to have a newline.

You are probably not getting this at work because whatever editor you use at work is probably adding newlines at the ends of text lines and the editor you're using at home isn't.

Community
  • 1
  • 1
Dour High Arch
  • 21,513
  • 29
  • 75
  • 90