Eric Sosman said:
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).