Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none?

Reply
Thread Tools

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

 
 
Keith Thompson
Guest
Posts: n/a
 
      09-11-2011
Eric Sosman <(E-Mail Removed)> writes:
> On 9/10/2011 3:10 AM, Keith Thompson wrote:
>> Eric Sosman<(E-Mail Removed)> writes:
>>> On 9/9/2011 4:46 PM, Jimmy wrote:
>>>> 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?
>>>
>>> Because it's required. 5.1.1.2p2:
>>>
>>> A source file that is not empty shall end in a new-line
>>> character, which shall not be immediately preceded by a
>>> backslash character [...]

>>
>> Yes, but that's not a constraint, which means that a compiler isn't
>> required to complain about it. [...]

>
> Surely emacs is within its rights to recommend that a source
> file be well-formed, even if the compiler is not required to diagnose
> deviations?
>
> Heck, emacs goes so far as to suggest line indentations, which
> the compiler doesn't need at all.


Of course. vim (at least by default) doesn't even allow you to create a
file without a trailing newline.

But emacs isn't asking about the newline because C needs it; it does
that for all text files.

I was merely quibbling about the word "required".

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Jimmy
Guest
Posts: n/a
 
      09-11-2011
On Sun, 11 Sep 2011 12:45:38 +0000, Kenny McCormack wrote:
> In article <(E-Mail Removed)>, Patrick Scheible
> <(E-Mail Removed)> wrote:
>>Nomen Nescio <(E-Mail Removed)> writes:
>>
>>> Hey asshole, nobody wants to see your sorry ass leftist signature when
>>> you quote a whole post just to follow up with a one-liner. Eat ****
>>> commie!

>>
>>Just for the record, at least one person thought it was an amusing
>>signature and enjoyed seeing it.
>>
>>-- Patrick

>
> Thanks. In any case, I doubt anyone is going to give a second thought
> to "Nomen"'s juvenile outburst.


I found the sig funny and insightful too. Pretty depressing that the
lunatic GOP fringe spout their incoherent bullshit even on a day like
today. Their ludicrous dick-waving in Iraq successfully destroyed every
ounce of sympathy the rest of the world had for our country in the wake
of the 9/11 attacks. Bush and his cronies made the world a more dangerous
place: and America a less safe country. Nice work, ass hats.

Anyway, thanks for all the responses - guess I'll just accept emacs'
offer to add an extra newline at the end of my files.

Sincerely,
Jimmy
 
Reply With Quote
 
 
 
 
Kelsey Bjarnason
Guest
Posts: n/a
 
      09-20-2011
On Sat, 10 Sep 2011 20:46:51 -0700, Patrick Scheible wrote:

> Nomen Nescio <(E-Mail Removed)> writes:
>
>> Hey asshole, nobody wants to see your sorry ass leftist signature when
>> you quote a whole post just to follow up with a one-liner. Eat ****
>> commie!

>
> Just for the record, at least one person thought it was an amusing
> signature and enjoyed seeing it.
>
> -- Patrick


Two.
 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      09-21-2011
Jimmy <(E-Mail Removed)> wrote:
> ... guess I'll just accept emacs' offer to add an extra
> newline at the end of my files.


It's not an 'extra' newline. It's the terminating newline
for the last line in the file. If it added an empty line
at the end of your files, *then* it would be an extra
newline.

But where emacs and C are coming from is that some systems
actually require a trailing newline. A good example is old
line printers that wouldn't print the last line until it
was given a newline character that prompted it to dump it's
line buffer.

Perhaps more practically, consider the header files in a
program that begins...

#include <stdio.h>
#include <stdlib.h>

If the header <stdio.h> didn't end with a newline then
the first line of <stdlib.h> may be merged with the last
line of <stdio.h> producing, say...

#endif#ifndef __stdlib

....which would likely result in a compilation error.

Certainly this is an issue if you're dumping a lot of
text files (e.g. with more, less or TYPE.) Adding the
newline tends to be *much* less of an inconvenience than
not adding it.

--
Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none? Jimmy C Programming 3 09-09-2011 10:36 PM
farming automation [parallel testing on multipe remote machines atthe same time] Cristina Ruby 2 07-16-2010 02:52 AM
[Python 2.6] print_function and unicode_literals cannot be used atthe same time? ܼĸ Python 3 10-29-2008 03:07 AM
file.read() returns an emtpy even if its currenet position is not atthe end js Python 2 04-22-2007 11:18 PM
Is splint really better than lint? Is there a better tool than splint? Peter Bencsik C Programming 2 09-21-2006 10:02 PM



Advertisments