|
|
发表于 2005-11-30 00:50:41
|
显示全部楼层
From Practical C Progarmming: The End-of-Line Puzzle
Back in the dark ages BC (Before Computers), a magical device called a Teletype
Model 33 existed. This amazing machine contained a shift register made out of a
motor, with a rotor, and a keyboard ROM consisting solely of levers and springs. It
contained a keyboard, a printer, and a paper tape reader/punch. It could transmit
messages over the phones using a modem at the rate of 10 characters a second.
The Teletype had a problem. It took two-tenths of a second to move the printhead
from the right side to the left. Two-tenths of a second is two character times. If a
second character came while the printhead was in the middle of a return, that
character was lost.
The Teletype people solved this problem by making end-of-line two characters:
<RETURN> to position the printhead at the left margin and <LINE FEED> to move
the paper up one line.
When the early computers came out, some designers realized that using two
characters for end-of-line wasted storage (at this time, storage was very expensive).
Some picked <LINE FEED> for their end-of-line, some <RETURN>. Some of the
diehards stayed with the two -character sequence.
UNIX uses <LINE FEED> for end-of-line. The newline character, \n, is code 0x0A
(LF or <LINE FEED>). MS-DOS/Windows uses the two characters: <LINE
FEED><RETURN>. Apple uses <RETURN>. |
|