[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LF/CR conversion



Paul Schlyter wrote:
In article <_JmdnVMGJZtlzjTYnZ2dnUVZ_rOqnZ2d@comcast.com>,
Michael J. Mahon <mjmahon@aol.com> wrote:


I only replaced characters, never altering the length of the file.  I
replaced CR/LF with blank/CR and LF alone with CR.  a cheap hack, but
it did what I needed.


Doing so can sometimes cause unwanted side effects.

If the text is a C or C++ source file, and if that file contains line
continuation characters (a backslash at the very end of a line), doing
what you did will add an extra space character after that final
baskslash, and that will invalidate the backslash.  The C compiler
will interpret the "\ " as a single space character, and as far as the
C compiler is concerner, there won't be any line continuation.  This
will frequently generate syntax errors when compiling the code - or, which
is worse, may be syntactically OK but do something different than the
programmer intended.

Programmers which encounter this kind of error usually get very
confused: since the extra trailing space behind the backslash will be
invisible in most text editors, they look at the code in their editor,
thinking it looks correct (which it would be without that trailing
space), and then get quite frustrated why the compiler says there's a
syntax error.

Right.

I did call it a cheap hack.  ;-)  It worked fine for text files
I wanted.

-michael

NadaNet networking for Apple II computers!
Home page:  http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it's seriously underused."