Re: New-line fight: Comment -vs- the end of source file
peter koch wrote:
James Kanze wrote:
Kaba wrote:
ISO 14882 international C++ standard says:
2.1/2: ... If a source file that is not empty does not end
in a new-line character, or ends in a new-line character
immediately preceded by backslash, the behaviour is
undefined.
I've always been irritated by the requirement that a file must
end in a new-line. It just comes to me automatically to leave
the last row without an new-line.
What kind of program editor do you use? I can't imagine a
program editor not ending a file it writes with a new line.
(For whatever historical reasons, we view programs as a sequence
of lines, e.g. the error messages from the compiler give a line
number. Given this, it would seem logical that any program
editor be line based, or at least give the impression of being
so when editing code.)
[snip]
In practice, I cannot see a system where it is possible to
generate a text file which doesn't end in a newline (it's not
possible on most systems---Windows and Unix are exceptions in
this regard), where it is not reasonably easy to read the
trailing data and detect the error. So in practice, I would
expect an error message from the compiler. I would still favor
keeping the requirement, however, since copying such files to
another system could easily result in the last line missing.
[snip]
We seem to come from different worlds, James.... all the
Visual Studio editors, I've used allow me to not put an empty
line at the bottom and so does e.g. notepad. Why on earth
would a text-editor submit a blank line in the end of a random
text?
Because text isn't random. In the case of a C++ program (and in
a lot of other cases as well), it is a sequence of lines (which
are formed from a sequence of words/tokes, which are formed from
a sequence of letters). A work processor (like Word) doesn't
treat it as such, and breaks lines according to its whim when
displaying and printing, but C++ programs are normally treated
as a sequence of lines, in which YOU have inserted the breaks.
Given this, it's up to the text editor to save the file as a
sequence of lines. Under Windows, the "definition" of a "line"
in the file system is a sequence of characters ending in a CRLF,
so each line in the editor ends up being written this way.
At least that is the way I understand it (but my understanding
may be influenced by Unix). Another possible definition could
be that a line is a sequence of characters, with multiple lines
being separated by a CRLF. (The classical separator vs.
terminator distinction.) If this is the case, it is impossible
to write a text file which doesn't end with a new-line, so the
problem doesn't exist (unless you intentionally create a file
with a \ as the last character).
Unless the editor was made especially for editing of c/C++
files I can't see a reason (but there are reasons not to).
Well, when I edit C++, I use an editor made (or at least
configured) for C++. I've gotten used to things like automatic
indentation, syntax highlighting, and the rest. And the Visual
Studios editor certainly handles all of this well; it's
knowledge of C++ is generally better than that of the editors I
normally use. (I find the general Windows environment a bit
Mickey Mouse, with a lot of showy gimicks, but little useful
features. On the other hand, the individual programs within the
environment, such as the compiler, are often better than many of
their Unix counterparts. The editor has at least some features
which are better than those in the editors I know well, and if I
could only get it to run on my machine, a Sun Sparc under
Solaris, I'd give it a serious try.)
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]