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?

 
 
Jimmy
Guest
Posts: n/a
 
      09-09-2011
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
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      09-10-2011
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 [...]

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      09-10-2011
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. It also means that the behavior of the
program is undefined.

In practice, one of the following will probably happen (in descending
order of likelihood, according to my vague guess):

1. The compiler warns about the missing newline but compiles the
file as if it were there.

2. The compiler doesn't warn about the missing newline but compiles
the file as if it were there.

3. The compiler prints an error message and rejects the source file.

4. The compiler compiles the source file without complaint as if
the last line were not there at all (leading to a possible syntax
error depending on what the last line looks like).

5. Something other arbitrarily bad thing happens.

To answer your question, a C source file should always end with
a newline. To answer your question about a blank rather than
a newline, I'm not entirely sure what you're asking. It's not
necessary to have either a space character or an empty line at the
end of a source file, just a newline character to terminate the last
line. For example, the last three characters of your file might be
'\n', '}', '\n' (on a system that uses '\n' to terminate lines).

--
Keith Thompson (The_Other_Keith) (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
 
Eric Sosman
Guest
Posts: n/a
 
      09-10-2011
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.

--
Eric Sosman
(E-Mail Removed)d
 
Reply With Quote
 
Roberto Waltman
Guest
Posts: n/a
 
      09-10-2011
Eric Sosman wrote:

> Surely emacs is within its rights to ...


Interesting. It seems not only corporations "are persons under the
law", but text editors were also granted personhood while I was not
looking ... ;
--
Roberto Waltman

[ Please reply to the group,
return address is invalid ]
 
Reply With Quote
 
ec429
Guest
Posts: n/a
 
      09-10-2011
On 10/09/11 16:36, Roberto Waltman wrote:
> Eric Sosman wrote:
>> Surely emacs is within its rights to ...

> Interesting. It seems not only corporations "are persons under the
> law", but text editors were also granted personhood while I was not
> looking ... ;

Only emacs, and only since someone added self_aware.el to the library.
It was bound to happen eventually - LISP's always been a favourite
language of AI researchers...
-E
--
'sane', adj.: see 'unimaginative'
on the web - http://jttlov.no-ip.org
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      09-10-2011
In article <(E-Mail Removed)>,
Roberto Waltman <(E-Mail Removed)> wrote:
>Eric Sosman wrote:
>
>> Surely emacs is within its rights to ...

>
>Interesting. It seems not only corporations "are persons under the
>law", but text editors were also granted personhood while I was not
>looking ... ;


Don't anthropomorphize computers (or text editors). They hate that.

--
"Remember when teachers, public employees, Planned Parenthood, NPR and PBS
crashed the stock market, wiped out half of our 401Ks, took trillions in
TARP money, spilled oil in the Gulf of Mexico, gave themselves billions in
bonuses, and paid no taxes? Yeah, me neither."
 
Reply With Quote
 
Nomen Nescio
Guest
Posts: n/a
 
      09-10-2011
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!

 
Reply With Quote
 
Patrick Scheible
Guest
Posts: n/a
 
      09-11-2011
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
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      09-11-2011
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.

--
Windows 95 n. (Win-doze): A 32 bit extension to a 16 bit user interface for
an 8 bit operating system based on a 4 bit architecture from a 2 bit company
that can't stand 1 bit of competition.

Modern day upgrade --> Windows XP Professional x64: Windows is now a 64 bit
tweak of a 32 bit extension to a 16 bit user interface for an 8 bit
operating system based on a 4 bit architecture from a 2 bit company that
can't stand 1 bit of competition.
 
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