warning: no newline at end of file

P

padam.singh

Hi,

I enable All Warnings during compiling my programs.

What is the significance of this warning:
warning: no newline at end of file

I use gcc to compile, but wonder why it needs a newline at end of the
file!

Any clues???

TIA,
Padam J Singh.
 
S

SM Ryan

(e-mail address removed) wrote:
# Hi,
#
# I enable All Warnings during compiling my programs.
#
# What is the significance of this warning:
# warning: no newline at end of file

The last character(s) of the file are not \n or \r or \r\n or \x1F
or whatever other marker your system uses for text files.

# I use gcc to compile, but wonder why it needs a newline at end of the
# file!

Couldd indicate a corrupted file. And it causes problems with some C
preprocessors.

Suppose you have a file bravo with
#if 0<NL>
abc<NL>
#endif<EOF>
and called it as
#include "alfa"<NL>
#include "bravo"<NL>
#include "charlie"<NL>
then sometimes that gets treated as
(contents of alfa)
#if 0<NL>
abc<NL>
#endif#include "charlie"<NL>
 
R

Robert W Hand

I enable All Warnings during compiling my programs.

What is the significance of this warning:
warning: no newline at end of file

It's required by the C Standard. See 5.1.1.2/2. "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." I understand that it was included to promote
independence among source files of a translation unit, by requiring
each included source file be composed of a sequence of complete lines.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top