News for hackers. Stuff that matters.
Re:Getting the ^D by animal_spirits on Sunday April 09, 2023 @09:11PM (#35508119)
My feedback for this is to change the title. It's dumb and gross.
Re:Getting the ^D by shamwow_ on Sunday April 09, 2023 @09:30PM (#35508237)
It made me chuckle, maybe take a joke?
[dead]
Re:Getting the ^D by eru on Sunday April 09, 2023 @09:57PM (#35508403)
> Tech is very male dominated and the more inclusive we are the more ideas we bring to the table.

Tech has been bending over backwards for quite a while, but to no avail.

In contrast, marketing, law, medicine etc used to be very male dominated a few decades ago, made almost no attempt at welcoming women, and still got many of them.

It's almost as if women make their own choices, and it's not really down to how welcoming specific fields are? It's almost as if women have preferences of their own? Who would have guessed?

See https://slatestarcodex.com/2017/08/01/gender-imbalances-are-... and https://slatestarcodex.com/2017/08/07/contra-grant-on-exagge...

Re:Getting the ^D by zephyrnh on Sunday April 09, 2023 @10:29PM (#35508572)
> Tech has been bending over backwards for quite a while, but to no avail.

You're applying a false equivalence here. Some things are positive changes and make sense, and some are not. Grouping everything together isn't helpful.

I am male, and my first thought on reading the title was that it was juvenile to a point that I was surprised to see it as a title on HN. Hearing someone else echo that feedback is helpful and will hopefully help the author in their growth.

This is not a "bend over backwards" request, it's a dumb sexual joke on HN, and your response comes across as very condescending.

Re:Getting the ^D by ayknfsefb on Monday April 10, 2023 @08:25AM (#35511456)
> it was juvenile

> help the author in their growth

> your response comes across as very condescending

Lack of self-awareness and pathetic childish pearl-clutching go so well together.

Go cry to mommy about swearing on the internet if you can't handle it, maybe she can install a filter.

Re:Getting the ^D by eru on Monday April 10, 2023 @10:28PM (#35520008)
For what it's worth, I even partially agree with you.

I went back and noticed that the original comment is dead and flagged now. So I 'vouched' for it: I don't entirely agree with the contents, but I think it is part of a good debate.

Re:Getting the ^D by animal_spirits on Sunday April 09, 2023 @10:10PM (#35508469)
Do you think people make their own choices on where to work based on how comfortable they feel working in that environment?
Re:Getting the ^D by eru on Sunday April 09, 2023 @10:34PM (#35508600)
Partially. But obviously lots of other factors are important.

Have a look at the slatestarcodex essays for more detail. Scott Alexander writes better than me.

Re:Getting the ^D by ayknfsefb on Monday April 10, 2023 @09:03AM (#35511773)
If they can't handle a double entendre about penises on the Internet, they're going to have a rough time when they figure out that half the population have actual, flesh and blood penises attached to them every second of the day. Penises. Everywhere! Poor ladies, they'd never go outside again!

Or maybe they're not as pathetic as you're making out. Yeah, that.

Re:Getting the ^D by ars on Sunday April 09, 2023 @10:25PM (#35508551)
I googled ^D and didn't find any other meaning other than ctrl-D?

Some places said a D is short for Dick, but I don't see why that would be especially offensive to abuse victims because it seems to be used in a flirtatious way, not an abusive way.

Re:Getting the ^D by animal_spirits on Sunday April 09, 2023 @11:56PM (#35509041)
To give context, it's a reference to "getting the D" or "giving the D" which is slang for getting/giving someone 'dick' which is inappropriate considering this is a post about terminals.
Re:Getting the ^D by joshl32532 on Monday April 10, 2023 @12:41AM (#35509241)
This is why tech bro culture persist.
Re:Getting the ^D by AdieuToLogic on Monday April 10, 2023 @12:49AM (#35509279)
> This is why tech bro culture persist.

Because one person on the Internet interpreted a title as a double entendre and said so?

Re:Getting the ^D by joshl32532 on Tuesday April 11, 2023 @09:01PM (#35533779)
I have nothing to say if you insist that phrase is not a sexual innuendo.

There's so many ways to phrase the title, but the author has to use https://www.urbandictionary.com/define.php?term=Getting%20th....

Re:Getting the ^D by lifthrasiir on Monday April 10, 2023 @03:07AM (#35509878)
I initially didn't get either of you, all I can think of was a half-face emoticon. It turns out that "getting the D" means something (I'll refrain from explaining this), and with this context "take a joke" is really unacceptable---it means you know the joke and you think it's fine, which isn't.
Re:Getting the ^D by xoac on Monday April 10, 2023 @03:47AM (#35510066)
I don’t really get why this is so offensive. It’s some guy’s webpage, where we are just visitors, on which he has shared some knowledge with a title that plays on a double entendre. It’s not about taking a joke as it’s not something addressed to you at all. People need to stop being hall monitors on the internet. Just close the page, move on.
Re:Getting the ^D by mdp2021 on Monday April 10, 2023 @04:07AM (#35510178)
The title makes some absolute sense, so it is per se acceptable. You may take this case as a reminder to remain focused and disregard unnecessary potential lateral reads.
Re:Getting the ^D by lifthrasiir on Monday April 10, 2023 @04:14AM (#35510212)
I didn't take offense to the title; it is not even clear whether the author intended that joke (I didn't know that phrase so could the author). I merely pointed out that, if you think the author intended this particular joke, then it is inappropriate to say "take [the] joke".
Re:Getting the ^D by mdp2021 on Monday April 10, 2023 @03:58AM (#35510129)
Although, some of us had to actually think for a while to notice what may have triggered your comment.
Re:Getting the ^D by mdp2021 on Monday April 10, 2023 @07:03AM (#35511005)
Oh, the "guess what I was thinking" game again.

Ok, guessed: if your mind has filthy lenses, sniper, do not ask us to join you in your avoidable traits.

Re:Getting the ^D by shrubble on Sunday April 09, 2023 @09:53PM (#35508372)
The author takes the long way round and misses the point by a little bit.

ANSI C defines EOF, the 2nd edition by Kernighan and Ritchie page 151 states 'getchar returns the next input character each time it is called, or EOF when it encounters end of file. The symbolic constant EOF is defined in <stdio.h>.

The value is typically -1, bit tests should be written in terms of EOF so as to be independent of the specific value.'

Re:Getting the ^D by zabzonk on Sunday April 09, 2023 @10:08PM (#35508462)
perhaps point out that there is no actual EOF in a file in modern operating systems - i bang on about this here: https://latedev.wordpress.com/2012/12/04/all-about-eof/
Re:Getting the ^D by ksherlock on Sunday April 09, 2023 @10:52PM (#35508713)
The discussion is about how terminals and pseudo terminals handle control characters, specifically ^D / EOF / termios.c_cc[VEOF] which is a few layers below getchar(). man stty(1) or termios(5) for more information.
Re:Getting the ^D by AdieuToLogic on Sunday April 09, 2023 @11:47PM (#35508994)
EOF is also used to indicate error(s) in a stream.

Its value is platform dependent. As per the C++ standard[0]:

  It is a macro definition of type int that expands into
  a negative integral constant expression (generally, -1).
0 - https://cplusplus.com/reference/cstdio/EOF/
Re:Getting the ^D by lionkor on Monday April 10, 2023 @12:16AM (#35509125)
please do not use cplusplus.com, use cppreference instead. cplusplus.com often is wrong, out of date, or just missing things.
Re:Getting the ^D by AdieuToLogic on Monday April 10, 2023 @12:36AM (#35509219)
Noted.

Is this particular citation, "wrong, out of date, or just missing things"?

Re:Getting the ^D by lionkor on Monday April 10, 2023 @05:03PM (#35517386)
None of the above for this case, but generally not a good idea to look there. Instead: https://en.cppreference.com/w/c/io
Re:Getting the ^D by heywhatupboys on Sunday April 09, 2023 @11:01PM (#35508761)
does the program not simply receive ^D as a normal character? I thought i was up to the program to interpret it
Re:Getting the ^D by AdieuToLogic on Sunday April 09, 2023 @11:39PM (#35508955)
When a program reads from a pseudo-terminal device in "cooked mode"[0], ^D is the default control character to indicate "no more input will be made available."

A program reading from a file handle other than a pseudo-terminal or a pseudo-terminal set to be in "raw mode" will behave as you describe.

0 - https://en.wikipedia.org/wiki/Terminal_mode

Re:Getting the ^D by bawolff on Sunday April 09, 2023 @11:34PM (#35508926)
It does not. Its still up to the program with how it wants to deal with end of file though.
Re:Getting the ^D by tannhaeuser on Monday April 10, 2023 @02:27AM (#35509706)
Yes but the expectation still is to interpret it as "end of input", even for interactive programs. One that doesn't (unfortunately) is zsh where ^D makes autosuggest prompt "do you wish to see all n possibilities?"
Re:Getting the ^D by userbinator on Monday April 10, 2023 @12:28AM (#35509179)
I like how he references Linus' TTY Demystified article (a popular repost here on HN too) --- that has almost become a de-facto source of information on the details of how the TTY subsystem works.
Re:Getting the ^D by donatj on Monday April 10, 2023 @01:40AM (#35509492)
Hmm, my assumption up to now had honestly been that ^D was just the shortcut for a NULL byte, 0x0 and everything just assumed it’d reached the end of the stream.

Sending a special EOT 0x4 that gets special terminal handling feels just a little less… elegant… than what I had imagined.

Re:Getting the ^D by wruza on Monday April 10, 2023 @02:06AM (#35509607)
Please look at ascii table to see why ctrl-{key} sends a corresponding control code and why the modifier is called “control”: https://www.commfront.com/pages/ascii-chart
Re:Getting the ^D by donatj on Monday April 10, 2023 @02:10AM (#35509625)
The article explained it well enough. Makes sense, I just was unaware. From that chart though then could ^` generate a NULL byte?
Re:Getting the ^D by proto_lambda on Monday April 10, 2023 @02:58AM (#35509834)
The chart also lists the control key combination for each control byte, for NUL, it's C-@.
Re:Getting the ^D by jwilk on Monday April 10, 2023 @06:17AM (#35510765)
^` works too.
Re:Getting the ^D by tuukkah on Monday April 10, 2023 @02:15AM (#35509652)
If EOF was a character, you couldn't process (binary) streams that contain the character.

^@ produces the NUL character.

Re:Getting the ^D by 1vuio0pswjnm7 on Monday April 10, 2023 @04:02AM (#35510155)
"I am curious now, would it be possible to make the keyboard generate a NULL byte either by existing keyboard shortcut or custom hardware - and how would the system handle it?"

Not sure I understand the point of the experiment, but in NetBSD kernel one can remap the keyboard, e.g., set a key to 0x00. How to do this in Linux kernel is a question for reader.

https://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/dev...

Re:Getting the ^D by layer8 on Monday April 10, 2023 @08:13AM (#35511389)
The NUL byte has no special meaning in file I/O, or the terminal. (Historically, the only special meaning was as a no-op character that does nothing.) The convention of using NUL as a termination character only exists for in-memory strings in C, and has no connection to file I/O.
Re:Getting the ^D by jwilk on Monday April 10, 2023 @03:15AM (#35509925)
> the process has to be programmed to stop if read returns no bytes. A process could carry on regardless, or not read stdin at all. In Bash, if you type half a command and press ^D repeatedly, nothing happens.

It's not a good example, because bash disables the canonical mode. When you type ^D this happens:

  read(0, "\4", 1)                        = 1
(And then bash ignores the read EOT character.)
Re:Getting the ^D by rhooke on Monday April 10, 2023 @06:29AM (#35510825)
Author here. You're correct. I've added a footnote to that part now. I think it still illustrates the point so I've left the main text alone.
Re:Getting the ^D by jeffrallen on Monday April 10, 2023 @04:30AM (#35510293)
See also the evil interview question, "how does a keyboard type characters into an Emacs buffer?"

You could spend 8 hours describing it from power, to USB descriptors, to debouncing, to keymapping, to matrix scanning, to ptys, to editor string management algorithms to Lisp. And passing by this article as well!

Re:Getting the ^D by codethief on Monday April 10, 2023 @05:02AM (#35510448)
Do you have a link? I can't find anything under that title.
Re:Getting the ^D by jeffrallen on Monday April 10, 2023 @05:13AM (#35510494)
Nah it's just an interesting interview question if you are looking for a generalist. There's also "what happens when you type into the address bar of your browser and hit return?" Can cover DNS, wifi, BGP, servers, DOM layout, TLS, etc.
Re:Getting the ^D by jwilk on Monday April 10, 2023 @06:23AM (#35510798)
Re:Getting the ^D by hun3 on Monday April 10, 2023 @09:14AM (#35511867)
The `c_cc` array is configurable via the stty command or the termios(3) API.

To override the character for "EOF," change ^D to something else in the following command and run it:

  stty eof ^D