Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | 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? |
| Date | 2011-09-10 00:10 -0700 |
| Organization | None to speak of |
| Message-ID | <lnobysc1p9.fsf@nuthaus.mib.org> (permalink) |
| References | <j4dtve$kj3$1@speranza.aioe.org> <j4eb8i$uoo$1@dont-email.me> |
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"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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? 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
csiph-web