Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the meaning of "warning : No new line at end of file"? [duplicate]

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 ?

like image 801
Jeegar Patel Avatar asked Nov 17 '11 18:11

Jeegar Patel


People also ask

How do I fix warning no newline at end of file?

Open the file in an editor, go to the last line of the file, and hit enter to add a blank line to the end of the file. Though, besides that, you should be using #include <iostream> instead of <iostream. h> . Then put in a using std::cout; after it.

What does no newline at end of file mean?

It indicates that you do not have a newline (usually '\n' , aka CR or CRLF) at the end of file. That is, simply speaking, the last byte (or bytes if you're on Windows) in the file is not a newline.

What's the point in adding a new line to the end of a file?

If content is added to the end of the file, then the line that was previously the last line will have been edited to include a newline character. This means that blame ing the file to find out when that line was last edited will show the text addition, not the commit before that you actually wanted to see.

Is every file on New line?

So, it turns out that, according to POSIX, every text file (including Ruby and JavaScript source files) should end with a \n , or “newline” (not “a new line”) character. This acts as the eol , or the “end of line” character. It is a line “terminator”.


2 Answers

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)

like image 73
James McNellis Avatar answered Nov 15 '22 06:11

James McNellis


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.

like image 29
Dour High Arch Avatar answered Nov 15 '22 06:11

Dour High Arch