Hacker Newsnew | past | comments | ask | show | jobs | submit | Isamu's commentslogin

Going all the way back to the earliest C compilers on DOS. There was a decision made to make “\n” just work on DOS for portability of Unix programs, and to make the examples from the C programming book just work.

But in Unix “\n” is a single byte, and in DOS it is 2. So they introduced text and binary modes for files on DOS. Behind the scenes the library will handle the extra byte. This is not necessary in Unix.

I used to have to be careful about importing files to DOS. Did the file come from Unix?


Linefeed (\n) is a single byte in DOS as well.

I think you are talking about carriage return linefeed pair (CRLF or \r\n),

These control codes go back to line printers. Linefeed advances the paper one line and carriage return moves the print head to the left.


>Linefeed (\n) is a single byte in DOS as well.

In binary mode. In text mode if you printf(“Hello World\n”) you get CRLF because that’s how text works on DOS. Unix had the convention of only requiring the LF for text. And Unix didn’t have text/binary modes. That’s the compatibility hack on DOS.

>These control codes go back to line printers.

Back to teletypes even. Believe me, I go back to line printers.


I'm pretty sure that conversion was done by the C library, just as stated in the article. Not by DOS. ASCII 0x0A '\n' is always one byte*, and C library implementations for DOS would insert an ASCII 0x0D '\r' byte before it at output time if the C FILE stream had been opened in text mode.

Note that printf(), which you use in your example, is a C library function that writes writes to a predefined text mode stream. So it follows the same rules.

I wasn't able to dig up the source code of a vintage DOS compiler's C library in a few minutes of looking, so I can't prove it right now, but this section of the C standard (7.21.2 - Streams) hints that my recollection is correct:

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf#p...

*(On systems where the char type is one byte, of course, which is the case for DOS C compilers.)


I wrote a C Standard library for MS/PC/DR-DOS. Your recollection is correct.

Thanks for confirming!

Agreed, I didn’t mean that DOS somehow converted it, this was a compatibility feature put into the C library.

Yes, and the order is important.

Sending a carriage return and linefeed to a TTY 33 and then printing works fine. Doing them in the opposite order, if the carriage is to the right of the page, will result in a linefeed (platen rotation) happening quickly, then the carriage starting to move left to the beginning of the next line, and then the next printed character will print wherever the carriage happens to be at the time - not yet to the left. So you will be missing a character at the beginning of the line because it's in between the two lines in an unexpected column-ish.

I have run into (in my mind, "hipster") code where the programmer for some reason reversed the order of CR and LF.


Teletypes is what I meant to say, thank you. Line printers have no carriage return mechanism.

Annoyingly I actually think '\r\n' is the correct line ending here - advance the paper and return the carriage, but I suppose unix took the simpler implementation which makes looping over characters, words (split by ' ') and lines (split by '\n') simpler as each loop only has a single comparison

The carriage return and linefeed combo are the commands to move to the next line of a teletype. Other commands might (in theory) be used for this purpose on other devices. These are implementation details.

Text inside a computer doesn't need any of that just to signal a newline. UNIX chose to use a single line feed character as a line separator because there was no good reason to use two. MacOS chose a single carriage return for similar reasons. Anything going out to a printer or teletype would run through a device driver that would turn the newline character into whatever the device expects.

Windows copied DOS which copied CP/M which was a very basic program loader for 8-bit machines and didn't really have "drivers" like we think of them today. I'm guessing here, but I imagine they chose the teletype combo because that's what most serial printers understood and printing was a major use case for those machines. That was probably the right choice for CP/M, but I can't imagine Microsoft would choose it if they were developing Windows from scratch today.


Yep, on Unixen the translation of CRLF to LF when printing to the terminal (and from CR to CRLF when reading input from the terminal) is done in the kernel, it's called "line discipline".

And if you switch the tty from "cooked" to "raw" mode then it doesn't do the conversion, and a CR just moves the cursor back to the start of the line and a LF just moves the cursor one line down.

Which is how you do the fun spinny icons on the command line without having to invoke ncurses!

You can also just use a \r directly without a \n. For example:

    spin='/-\|'
    while true; do 
      i=$(( (i+1) % 4 ))
      printf "\r${spin:$i:1} Working..."
      sleep 0.1
    done

By the way yes, that is a subtle reference to the TOS computer, so it's best read in that voice :-)

> So they introduced text and binary modes for files on DOS

It actually long predates DOS

C stdio is descended from Mike Lesk’s “portable IO package” (original release circa 1973). Bell Labs ported their C compiler from Unix to Honeywell GCOS and IBM S/370 mainframes. Mainframes handle text files very differently from how Unix systems do-it is much more complex than simply changing the newline character. So in Lesk’s package, the mode parameter to copen() told you whether the file was text or binary. copen() was renamed to fopen(), and the character to indicate binary mode was changed from “i” to “b”, and hence stdio

stdio has always had text-vs-binary file distinction, on some platforms (such as Unix) it has always been a no-op, on others it hasn’t

https://archive.org/details/lesk-iolib


Similarly on Classic Mac OS, C compilers would map single '\n' to single '\r' which is what was the Mac OS convention.

Genuinely interesting strategy, the term “poison” should really apply more to AI that depend on Wikipedia for training

>This strategy, in a likely attempt to evade global sanctions on Russian news outlets, is now poisoning AI tools and Wikipedia. By posing as authoritative sources on Wikipedia and reliable news outlets cited by popular large language models (LLMs), Russian tropes are rewriting the story of Russia’s war in Ukraine. The direct consequence is the exposure of Western audiences to content containing pro-Kremlin, anti-Ukrainian, and anti-Western messaging when using AI chatbots that rely on LLMs trained on material such as Wikipedia.


Fairly steady trends since 2000 with a drop during covid, America becoming less popular for Europeans and Americans

Copyright has a lot to do with what we as a society want to protect and encourage. We want to protect an author that put the hours into creating a book, as opposed to the person creating a copy of that work. The person copying can claim they put in work too but the claim is not strong enough to override our preference to protect original authors.

Part of the problem with generated works is that it is lower effort like the person copying something. It’s not an activity that demands special protection like original authorship. I believe this is a large part of the reasoning.


AI is a monster to our current copyright system - monster in the philosophical sense, that is, an example that destroys the concept.

First, its creation is (claimed to be) extremely useful for society, but in order to be created it requires ignoring copyright for pretty much everything ever written. Something we kinda shrugged under the table.

Then, it introduces an extreme jump down in creation effort - so if the focus is protection of effortful creation, nothing with AI use qualifies. But of course, you'd want society to benefit from effortlessness in general, spending more effort than needed in a task is the opposite of efficiency.


I recommend the Asianometry channel, he has a good series of videos about ASML, TSMC, chip fab supply chain, the Japan photo resist monopoly, etc

https://m.youtube.com/c/Asianometry/videos?ra=m


Asianometry is fantastic

More posts please relating to conservator tech or websites. Thanks.

When written horizontally it is now left to right but earlier you would see horizontal right to left. But vertical was preferred especially in the past.

You can see horizontal train stop signs written right to left in “In This Corner of the World” anime. Today all signage seems to be left to right.

[edit] The history section in Wikipedia explains that this was a postwar script reform. https://en.wikipedia.org/wiki/Japanese_writing_system


Horizontal right to left is an edge case of vertical writing with one character tall columns.

I have found that people who speak indirectly don’t agree that they are indirect, have no idea why you think they are not direct. It’s so ingrained it can’t be seen.

I have extreme examples from friends, where somehow they “hear” the opposite of what I say because they are always looking for the indirect meaning, not what you are saying.

Fun example from a friend: his family were extremely direct but his girlfriend’s family was very indirect. As a young naive guy he was having dinner with his girlfriend’s family and her father asked: “is there any salt” and my friend looked up at the glass salt shaker and said “yes” and continued with his meal.


> Fun example from a friend: his family were extremely direct but his girlfriend’s family was very indirect. As a young naive guy he was having dinner with his girlfriend’s family and her father asked: “is there any salt” and my friend looked up at the glass salt shaker and said “yes” and continued with his meal.

Are we supposed to side with your friend here? The fact that he couldn't infer that the father might want some salt is, at best, very shortsighted and pedantic. It's roughly equivalent to a teacher responding to "Can I go to the washroom?" with "I don't know, can you?" -- except in this case it's not said in jest.


Yeah it’s just meant to be funny, in a haha-been-there kind of way. It’s an example of Asperger’s -like thinking, overly literal. My friend was embarrassed in front of his gf, and he learned what indirect speaking was.

Indirect speakers don’t know they are speaking indirectly. They get upset with literal people, because “how could you not know what I mean? You must be a jerk!”


Every dumbass divorced Dad "she asked if the wash was done and I said yes"


IDK, I just do the normal-person thing of asking my question a different way when I don't get the result I was expecting instead of fuming about being misinterpreted.


>Without private property to accumulate or a state apparatus to capture, the reasoning goes, there would simply be nothing left to be corrupt about.

Right, it becomes mostly the corruption of power, and the lengths people will go to in order to retain it. It’s astonishing that is not recognized as a problem.


>Our safest robotics model yet Safety is integrated into every level of our embodied reasoning models. Gemini Robotics-ER 1.6 is our safest robotics model to date, demonstrating superior compliance with Gemini safety policies on adversarial spatial reasoning tasks compared to all previous generations.

The safety guidelines are interesting, they treat them as a goal that they are aspiring to achieve, which seems realistic. It’s not quite ready for prime time yet.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: