[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:47: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
11 Answers

Eric Sosman

9/10/2011 12:33:00 AM

0

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

Keith Thompson

9/10/2011 7:10:00 AM

0

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.ne...
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Eric Sosman

9/10/2011 1:17:00 PM

0

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

Roberto Waltman

9/10/2011 3:36:00 PM

0

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 ]

ec429

9/10/2011 3:56:00 PM

0

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...

gazelle

9/10/2011 5:43:00 PM

0

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."

Nomen Nescio

9/10/2011 9:57:00 PM

0

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!

Patrick Scheible

9/11/2011 3:47:00 AM

0

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

gazelle

9/11/2011 12:46:00 PM

0

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.

Keith Thompson

9/11/2011 5:55:00 PM

0

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.ne...
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"