"No newline at end of file" compiler warning
C+npls 03 Standard [2.1.1 .2] proclaims:
If a resource documents that is not vacant does not end in a new - line personality, or finishes in a new - line personality quickly come before by a backslash personality prior to any kind of such splicing happens, the actions is undefined.
Think of several of the troubles that can take place if there is no newline. According to the ANSI criterion the
#include of a documents at the starting inserts the documents specifically as it is to the front of the documents and also does not insert the new line after the
#include <foo.h> after the materials of the documents. So if you include a documents without newline at the end to the parser it will certainly be considered as if the last line of
foo.h gets on the very same line as the first line of
foo.cpp. What happens if the last line of foo.h was a comment without a new line? Currently the first line of
foo.cpp is commented out. These are simply a number of instances of the sorts of troubles that can approach.
Simply intended to aim any kind of interested events to James' solution listed below. While the above solution is still proper for C, the new C+npls typical (C+npls 11) has actually been transformed to make sure that this caution needs to no more be released if making use of C+npls and also a compiler satisfying C+npls 11.
From C+npls 11 typical using James' blog post:
A resource documents that is not vacant which does not end in a new - line personality, or that finishes in a new - line personality quickly come before by a backslash personality prior to any kind of such splicing happens, will be refined as if an added new - line personality were added to the documents (C+npls 11 cfr6.2.1cfr1).
It isn't describing an empty line, it is whether the last line (which can have web content in it) is ended with a newline.
The majority of full-screen editor will certainly place a newline at the end of the last line of a file, so if the last line does not have one, there is a threat that the file has actually been trimmed. Nonetheless, there stand reasons that you could not desire the newline so it is just a caution, not a mistake.