[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Is a blank at the end of a C file a better style than a newline at the end of the file or is it better to place none?

Jimmy

9/9/2011 8:46:00 PM

Hello everyone!

As the subject says. The reason for my question is that emacs always
suggest me to put a newline at the end of the C file if I forget to do
it. Why?

Sincerely,
Jimmy
3 Answers

James Kuyper

9/9/2011 9:05:00 PM

0

On 09/09/2011 04:46 PM, Jimmy wrote:
> Hello everyone!

You should always put your question in the body of the message. The
subject line should only be a summary (and it should be a shorter
summary than this one is.

> As the subject says. The reason for my question is that emacs always
> suggest me to put a newline at the end of the C file if I forget to do
> it. Why?

Because there are systems where the absence of such a newline will cause
your program to not be processed properly. The C standard has been
written to allow such systems to be fully conforming.

Joe Pfeiffer

9/9/2011 10:14:00 PM

0

Jimmy <nospam@trash.invalid> writes:

> Hello everyone!
>
> As the subject says. The reason for my question is that emacs always
> suggest me to put a newline at the end of the C file if I forget to do
> it. Why?

It makes the same suggestion for every sort of text file I've ever had
occasion to notice it on. There are lots of programs accepting text
input that assume every line of text ends with a newline, and which will
misbehave in various ways if that assumption is false (at one time
decades ago, the sh shell was one of those programs -- and if the last
line of a shell script didn't end with a newline, that last command
wasn't executed).

J. J. Farrell

9/9/2011 10:37:00 PM

0

Jimmy wrote:
>
> As the subject says.

I can't see all the subject, so I'll guess. Much better to put the
question in the message so people are more easily able to read and
comment on it.

> The reason for my question is that emacs always
> suggest me to put a newline at the end of the C file if I forget to do
> it. Why?

My best guess is that it's because every line in a text file
conventionally ends in a newline character; I've had other editors give
similar warnings on other types of text file.

If it's intelligent enough to understand that this particular file is
meant to be a C source file, then it may be because the C language
requires a non-empty source file to end with a non-escaped newline
character.