Mike Wahler said:
Dale said:
@justice.itsc.cuhk.edu.hk: [...]
(Did you copy the file from a Windows machine to a Unix box, by any
chance?
I once used a compiler that gagged on the ^M that Windows puts at the end
of every line.)
In Windows, '^M' is the (console's) glyph for the ASCII
character with value 13, the 'newline' character. If you
have a C compiler that can't handle newline characters
in a source file, dump it, fast.
Not quite. (The following is partially off-topic, but it's relevant
to the handling of text files and of C source files.)
In Windows text files, the end-of-line marker is a CR followed by an
LF (ASCII codes 10 and 13, respectively). If you read a Windows text
file in binary mode, you'll see the "\r\n" characters. If you read it
in text mode, the end-of-line marker will be translated to a single
"\n" character; C calls this a "newline" character, ASCII calls it
"LF" or line-feed.
Unix text files use a single LF character to mark the end of a line;
no translation is necessary when reading a file in either text or
binary mode.
(Note that a C compiler needn't be implemented in C, and needn't
necessarily follow the rules of C text files when reading source
files.)
If you copy a Windows text file to a Unix system without translating
the end-of-line markers, the result will be an invalid text file with
an extraneous '\r' character (also represented as "^M") at the end of
each line. Though a Unix compiler can legally ignore extraneous '\r'
characters, I don't believe it's required to.