Re: New-line fight: Comment -vs- the end of source file
Kaba wrote:
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.
Currently I use the editor in the Visual Studio 2005, but I
think it has worked the same in the previous versions also.
Specifically it is the header file boiler-plate code that
keeps me leaving the end-of-line out:
First I write
#ifndef FILE_H
#define FILE_H
#endif
Then after typing #endif I instantly move to the empty row and
start adding stuff. And I _never_ remember to push the enter
after the #endif:)
Funny, my editor inserts the boiler-plate automatically for me,
any time I open an inexistant file whose name ends in .hh.
(Obviously, I have defined the endings it recognizes and what it
inserts.) I'd be very surprised if the Visual Studio editor
doesn't offer the same possibility.
More to the point, even if I enter the text by hand, without the
trailing new line, the trailing new line is there in the
generated file. Although C++ doesn't require it, all of my
compilers are line oriented, displaying the line number for
error messages, etc. The editors take this into account, and
don't allow text that isn't in a line.
(I'm not familiar enough with Visual Studios to know how to
configure its editor, but it would seem very strange that it
cannot automatically generate boiler plate, nor automatically
ensure that the file ends with a new line. I've never actually
seen an editor which doesn't have the latter possibility.)
Minor inconvenience, yet irritating. I wonder if this
requirement could be removed?
I think it has to do with the way a compiler reads lines.
Depending on how it is done, it may not see the final,
non-terminated line.
Hmm.. I'd presume that the file reader would have to check for
the file- end marker anyway? For example, isn't that how
getline() behaves?
I think that the original problem was at a lower level. I'm not
sure that it's still relevant, however.
So in practice, I would expect an error message from the
compiler.
You can get Visual C++ to generate an error by disabling the
Microsoft specific language extensions.
especially by those that are starting on C++. And, I can't
imagine any compiler not doing the right thing in this
situation anyway.
You mean, emit a warning or an error?
In effect, pretend that the newline was there before the end-of-file
marker.
And what happens if the last character in the file is a '\'? Or
if the system isn't capable of returning data from a text file
if the data doesn't end with a '\n'? (I suppose that for the
first, you could say that the compiler should process all files
as if they had two additional trailing new lines, and I doubt
that the second is really relevant today.)
--
James Kanze GABI Software
Conseils en informatique orient9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S9mard, 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 ]