warning : no new line at end of file

S

Sameer

Hi,
when i compile my C programs (even 2 line progs) give the warning, no
new line at end of file.
What does this mean ?
-Regards,
Sameer
 
R

Rahul Chandok

Hi,

Can you please type the program you are trying to compile.

It would be helpful for us if you tell us the compilation environment.
for e.g. OS used and compiler version used.

Rahul
 
K

Keith Thompson

Sameer said:
when i compile my C programs (even 2 line progs) give the warning, no
new line at end of file.
What does this mean ?

It means there's no newline at the end of the file. What do you think
it means?

In your text editor, add a newline to the end of the file you're
trying to compile. (Some editors do this automatically; yours
apparently doesn't.)
 
C

Chuck F.

Sameer said:
>
Hi, when i compile my C programs (even 2 line progs) give the
warning, no new line at end of file. What does this mean ?

It means that there was no newline character at the end of the
source file. You must be failing to hit <ret> (or <enter>) after
typing the last source line in your editor.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
R

Richard Bos

Sameer said:
when i compile my C programs (even 2 line progs) give the warning, no
new line at end of file.

It means, surprise, surprise, that there is no new-line at the end of
your source file. Quoth the Standard:

# A source file that is not empty shall end in a new-line character

Richard
 
S

Sameer

this is the source code :

#include <stdio.h>

main()
{
printf("hi\n") ;

}
when i compile it i get
warning: no new line at end of file
I am using madrake linux and compiling it with gcc
 
J

John Smith

It means, surprise, surprise, that there is no new-line at the end of
your source file. Quoth the Standard:

# A source file that is not empty shall end in a new-line character

So the next obvious question is to ask why it is this way?

I personally think it's one of the most dumb restrictions ever made. Does it
change anything about how the program is compiled? No! I mean, who cares
about blank lines. It's the code which is important.

Apple also seems to have disabled this in their version of gcc on Mac OS X.

-- John
 
R

Richard Heathfield

[Followups set to comp.lang.c]

John Smith said:
So the next obvious question is to ask why it is this way?

Presumably because a source file is intended to be a text file, and a text
file comprises zero or more lines, and a line comprises zero or more
characters terminated by a newline character.
 
R

Richard Bos

John Smith said:
So the next obvious question is to ask why it is this way?

Because there are OSes where a text file is stranger even than the
mindset of a Unix-head.
I personally think it's one of the most dumb restrictions ever made. Does it
change anything about how the program is compiled? No! I mean, who cares
about blank lines.

The restriction is not on blank lines; the restriction is that the final
line, like all the others, must be properly terminated.

Not all the world is a toy OS from Berzerkeley, you know.

Richard
 
V

Valentin Nechayev

Thu, Dec 29, 2005 at 10:48:30, js (John Smith) wrote about "warning : no new line at end of file":
JS> So the next obvious question is to ask why it is this way?

Because unterminated text line isn't proper text line.

JS> I personally think it's one of the most dumb restrictions ever made. Does it
JS> change anything about how the program is compiled? No! I mean, who cares
JS> about blank lines. It's the code which is important.
JS> Apple also seems to have disabled this in their version of gcc on Mac OS X.

Stock gcc doesn't require termination of last line, but warns for
its.


-netch-
 
A

Afifov

you must declare main to be int and return 0. The person with the first
post excluded the return statement, which i was referring to.
 
C

Chuck F.

Afifov said:
you must declare main to be int and return 0. The person with
the first post excluded the return statement, which i was
referring to.

Who is 'you'? The first post in this newsgroup occurred something
like 40 years ago, and I don't think it is available anywhere.
Some people cooperate and include proper context and attributions
in their reply articles. Other rude ones don't bother and just
waste everybodies time and bandwidth.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
N

Niklas Norrthon

Sameer said:
Hi,
when i compile my C programs (even 2 line progs) give the warning, no
new line at end of file.
What does this mean ?

It means that there isn't a newline at the end of the file.

/Niklas Norrthon
 
N

Niklas Norrthon

Samer wrote earlier in the thread:


Afifov said:
could it be that you forgot void main()?!

Please provide context!!!

May I ask why you think a warning about a missing newline would
have anything to do with "void main()" whatever that is?

By the way in C main returns int. Always!

/Niklas Norrthon
 
K

Kenny McCormack

Who is 'you'? The first post in this newsgroup occurred something
like 40 years ago, and I don't think it is available anywhere.
Some people cooperate and include proper context and attributions
in their reply articles. Other rude ones don't bother and just
waste everybodies time and bandwidth.

You (and others, such as Keith) are wasting your breath. They'll never get
it. And I'll tell you why.

Imagine that there's a mouse - and the mouse is the Usenet. You and I can
see that it is a mouse and we behave accordingly. But now there is a class
of users (we'll call them "googlers") that are wearing these funny weird
glasses that make them see not a mouse, but an elephant. Seeing an
elephant (i.e., the Usenet as a web page), they also behave accordingly.
And no amount of verbiage from us is going to convince them that it's not
an elephant - that it is only a mouse.

To make this more clear, to a googler, it doesn't make any sense to "quote"
(whatever the heck that is...), in fact, to do so would be absurd, when all
the rest of the articles in the thread are right there in front of their
faces (just as clear as the trunk on that mouse, er, elephant). And no
amount of verbiage from us is going to convince them not to believe what
they see. The point is you can *never* convince someone that what they see
isn't reality. The only way you can address the problem is to help them
fix their eyesight (or help them remove their funny glasses).
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top