Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #10062 > unrolled thread

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?

Started byJimmy <nospam@trash.invalid>
First post2011-09-09 20:46 +0000
Last post2011-09-11 10:55 -0700
Articles 14 — 10 participants

Back to article view | Back to comp.lang.c


Contents

  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 <nospam@trash.invalid> - 2011-09-09 20:46 +0000
    Re: 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? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-09 20:32 -0400
      Re: 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? Keith Thompson <kst-u@mib.org> - 2011-09-10 00:10 -0700
        Re: 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? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-10 09:16 -0400
          Re: 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? Roberto Waltman <usenet@rwaltman.com> - 2011-09-10 11:36 -0400
            Re: 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? ec429 <ec429@cam.ac.uk> - 2011-09-10 16:55 +0100
            Re: 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? gazelle@shell.xmission.com (Kenny McCormack) - 2011-09-10 17:42 +0000
              Re: Is a blank at the end of a C file a better style than a newline at   none? Nomen Nescio <nobody@dizum.com> - 2011-09-10 23:57 +0200
                Re: Is a blank at the end of a C file a better style than a newline at   none? Patrick Scheible <kkt@zipcon.net> - 2011-09-10 20:46 -0700
                  Re: Is a blank at the end of a C file a better style than a newline at   none? gazelle@shell.xmission.com (Kenny McCormack) - 2011-09-11 12:45 +0000
                    Re: Is a blank at the end of a C file a better style than a newline at  none? Jimmy <nospam@trash.invalid> - 2011-09-11 19:21 +0000
                      Re: Is a blank at the end of a C file a better style than a newline at none? Peter Nilsson <airia@acay.com.au> - 2011-09-20 17:17 -0700
                  Re: Is a blank at the end of a C file a better style than a newline at  none? Kelsey Bjarnason <kbjarnason@gmail.com> - 2011-09-20 15:35 -0700
          Re: 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? Keith Thompson <kst-u@mib.org> - 2011-09-11 10:55 -0700

#10062 — 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?

FromJimmy <nospam@trash.invalid>
Date2011-09-09 20:46 +0000
SubjectIs 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?
Message-ID<j4dtve$kj3$1@speranza.aioe.org>
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

[toc] | [next] | [standalone]


#10077

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-09-09 20:32 -0400
Message-ID<j4eb8i$uoo$1@dont-email.me>
In reply to#10062
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
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#10084

FromKeith Thompson <kst-u@mib.org>
Date2011-09-10 00:10 -0700
Message-ID<lnobysc1p9.fsf@nuthaus.mib.org>
In reply to#10077
Eric Sosman <esosman@ieee-dot-org.invalid> 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) kst-u@mib.org  <http://www.ghoti.net/~kst>
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#10094

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-09-10 09:16 -0400
Message-ID<j4fo1r$ngf$1@dont-email.me>
In reply to#10084
On 9/10/2011 3:10 AM, Keith Thompson wrote:
> Eric Sosman<esosman@ieee-dot-org.invalid>  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
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#10096

FromRoberto Waltman <usenet@rwaltman.com>
Date2011-09-10 11:36 -0400
Message-ID<lk0n6713k39sk3s1v1kb51tlocm9shskvv@4ax.com>
In reply to#10094
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 ]

[toc] | [prev] | [next] | [standalone]


#10097

Fromec429 <ec429@cam.ac.uk>
Date2011-09-10 16:55 +0100
Message-ID<j4g1ab$eu7$1@dont-email.me>
In reply to#10096
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

[toc] | [prev] | [next] | [standalone]


#10099

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2011-09-10 17:42 +0000
Message-ID<j4g7iq$1og$1@news.xmission.com>
In reply to#10096
In article <lk0n6713k39sk3s1v1kb51tlocm9shskvv@4ax.com>,
Roberto Waltman  <usenet@rwaltman.com> 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."

[toc] | [prev] | [next] | [standalone]


#10114 — Re: Is a blank at the end of a C file a better style than a newline at none?

FromNomen Nescio <nobody@dizum.com>
Date2011-09-10 23:57 +0200
SubjectRe: Is a blank at the end of a C file a better style than a newline at none?
Message-ID<5578c0dfe869c8037572a4cbaa01b8ec@dizum.com>
In reply to#10099
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 shit commie!

[toc] | [prev] | [next] | [standalone]


#10121 — Re: Is a blank at the end of a C file a better style than a newline at none?

FromPatrick Scheible <kkt@zipcon.net>
Date2011-09-10 20:46 -0700
SubjectRe: Is a blank at the end of a C file a better style than a newline at none?
Message-ID<86pqj7wxjo.fsf@zipcon.net>
In reply to#10114
Nomen Nescio <nobody@dizum.com> 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 shit commie!

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

-- Patrick

[toc] | [prev] | [next] | [standalone]


#10129 — Re: Is a blank at the end of a C file a better style than a newline at none?

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2011-09-11 12:45 +0000
SubjectRe: Is a blank at the end of a C file a better style than a newline at none?
Message-ID<j4iahi$k84$2@news.xmission.com>
In reply to#10121
In article <86pqj7wxjo.fsf@zipcon.net>,
Patrick Scheible  <kkt@zipcon.net> wrote:
>Nomen Nescio <nobody@dizum.com> 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 shit 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.

[toc] | [prev] | [next] | [standalone]


#10139 — Re: Is a blank at the end of a C file a better style than a newline at none?

FromJimmy <nospam@trash.invalid>
Date2011-09-11 19:21 +0000
SubjectRe: Is a blank at the end of a C file a better style than a newline at none?
Message-ID<j4j1o7$lfh$1@speranza.aioe.org>
In reply to#10129
On Sun, 11 Sep 2011 12:45:38 +0000, Kenny McCormack wrote:
> In article <86pqj7wxjo.fsf@zipcon.net>, Patrick Scheible 
> <kkt@zipcon.net> wrote:
>>Nomen Nescio <nobody@dizum.com> 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 shit
>>> 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

[toc] | [prev] | [next] | [standalone]


#10617 — Re: Is a blank at the end of a C file a better style than a newline at none?

FromPeter Nilsson <airia@acay.com.au>
Date2011-09-20 17:17 -0700
SubjectRe: Is a blank at the end of a C file a better style than a newline at none?
Message-ID<29a90c2a-aac5-48c8-8fe3-0378947d3398@n35g2000yqf.googlegroups.com>
In reply to#10139
Jimmy <nos...@trash.invalid> 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

[toc] | [prev] | [next] | [standalone]


#10614 — Re: Is a blank at the end of a C file a better style than a newline at none?

FromKelsey Bjarnason <kbjarnason@gmail.com>
Date2011-09-20 15:35 -0700
SubjectRe: Is a blank at the end of a C file a better style than a newline at none?
Message-ID<d2hnk8-6u5.ln1@spankydtr.localhost.net>
In reply to#10121
On Sat, 10 Sep 2011 20:46:51 -0700, Patrick Scheible wrote:

> Nomen Nescio <nobody@dizum.com> 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 shit
>> commie!
> 
> Just for the record, at least one person thought it was an amusing
> signature and enjoyed seeing it.
> 
> -- Patrick

Two.

[toc] | [prev] | [next] | [standalone]


#10135

FromKeith Thompson <kst-u@mib.org>
Date2011-09-11 10:55 -0700
Message-ID<lnk49farr6.fsf@nuthaus.mib.org>
In reply to#10094
Eric Sosman <esosman@ieee-dot-org.invalid> writes:
> On 9/10/2011 3:10 AM, Keith Thompson wrote:
>> Eric Sosman<esosman@ieee-dot-org.invalid>  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) kst-u@mib.org  <http://www.ghoti.net/~kst>
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web