Windows 換行符為什麼設計成 CR+LF?
為什麼不和 Unix 一樣用
呢,是技術上的原因還是單純搞標準?
是游標回到開頭,
是游標往下移一行,這樣子和打字機的工作原理類似。
不過,早在1968年,ISO標準就已經支持
和
為換行符了,那個時候連微軟甚至是UNIX都還沒有。不僅僅是微軟,早期的非unix操作系統,包括我們熟知的DOS、Symbian和PalmOS都使用
作為換行符。
參考:http://en.wikipedia.org/wiki/Line_break_(computing)
Wiki 上有說啊……簡單來說就是當時的電傳打字機使用 CR-LF 作為換行,其中 CR 將列印頭挪到行首,LF 將它移動到下一行。因為 CR 移動的距離更長,所以它在先,保證兩個字元發完列印頭一定可以移動到第二行的行頭。當時 DEC 的機器都是這麼乾的,後來 CP/M、DOS 就遵守了這個約定。Multics 則利用驅動分離了印表機和程序,所以使用單個 LF,這樣處理方便些。
ASCII was developed simultaneously by the ISO and the ASA, the predecessor organization to ANSI. During the period of 1963–1968, the ISO draft standards supported the use of either CR+LF or LF alone as a newline, while the ASA drafts supported only CR+LF.
The sequence CR+LF was in common use on many early computer systems that had adopted Teletype machines, typically a Teletype Model 33 ASR, as a console device, because this sequence was required to position those printers at the start of a new line. On these systems, text was often routinely composed to be compatible with these printers, since the concept of device drivers hiding such hardware details from the application was not yet well developed; applications had to talk directly to the Teletype machine and follow its conventions. In particular, this explains the names of the control characters, which signify the actions of an ordinary mechanical typewriter of the times: "Line Feed" is the action to switch to a new line, carried out by the paper feed mechanism of the typewriter carriage, and "Carriage Return" is the action to position the typing device at the beginning of the line, carried out by the sliding movement of the carriage.
Early teletype machines had a problem when a printing character followed the carriage return. It just printed it as a smudge, on-the-fly in the middle of the page, while it was moving the carriage back to the first position. "The solution was to make the newline two characters: CR to move the carriage to column one, and LF to move the paper up."[9]
Most minicomputer systems from DEC used this convention. CP/M used it as well, to print on the same terminals that minicomputers used. From there MS-DOS (1981) adopted CP/M"s CR+LF in order to be compatible, and this convention was inherited by Microsoft"s later Windows operating system.
The separation of the two functions concealed the fact that the print head could not return from the far right to the beginning of the next line in one-character time. That is why the sequence was always sent with the CR first. In fact, it was often necessary to send extra characters (extraneous CRs or NULs, which are ignored) to give the print head time to move to the left margin. Even many early video displays required multiple character times to scroll the display.
The Multics operating system began development in 1964 and used LF alone as its newline. Multics used a device driver to translate this character to whatever sequence a printer needed (including extra padding characters), and the single byte was much more convenient for programming. The seemingly more obvious choice of CR was not used, as a plain CR provided the useful function of overprinting one line with another to create Boldface and Strikethrough effects, and thus it was useful to not translate it.Unix followed the Multics practice, and later systems followed Unix.
那時,存儲器很貴,一些科學家認為在每行結尾加兩個字元太浪費了,加一個就可以。於是,就出現了分歧。
代表回車換行,是之前印表機衍生出來的
如果你對一個過時的設計感到不解, 那麼它多半是為了向後兼容.
由於打字機需要回車和換行2個操作來移到下一行的開頭, 雖然我從沒見過不回車而只換行的應用場景. 而 LF和CR+LF分別為ISO和ANSI的標準, 在設計上dos採用了後者, unix則採用了一個字元的設計.CR 和 LF 最初是控制電傳印表機(Teletype,所以 UNIX 裡面有個 tty,就是這玩意的縮寫)的,CR 把列印頭移動到行首,LF 把紙上卷一行,因為 CR 要的時間更長所以一般要求換行的過程裡面都是 CR 在前(有些早期設備甚至還會在 CR 和 LF 之間插 NUL,確保列印頭完成複位)。
DOS 從 DEC 和 CP/M 那裡繼承了這個設計,這樣文本文件的位元組序列可以直接控制印表機。作者:Belleve
鏈接:Unix/Linux/Mac 與 Windows 的換行符不統一的原因/目的是什麼? - Belleve 的回答來源:知乎著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請註明出處。
推薦閱讀:
※為什麼 Windows 在刪除正在使用的文件時會提示「文件已在 XX 中打開」並拒絕刪除,而安卓不會?
※為什麼 Windows 10 計算器應用中含開方計算結果不準確?
※聽說很多微軟員工自己不用 Windows,是真的嗎?
※為什麼蘋果美國工廠的 iMac 上運行的是 Windows 系統?
※有哪些關於 Windows 下 C++ 程序調試的書推薦?
TAG:MicrosoftWindows | Linux |