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

Your comment makes no sense. If it was designed for non-null terminated strings, why would it specifically pad after a null terminator?

I looked up the actual reason for its inception:

---

    Rationale for the ANSI C Programming Language", Silicon Press 1990.

    4.11.2.4 The strncpy function
    strncpy was initially introduced into the C library to deal with fixed-length name fields in structures such as directory entries. Such fields are not used in the same way as strings: the trailing null is unnecessary for a maximum-length field, and setting trailing bytes for shorter names to null assures efficient field-wise comparisons. strncpy is not by origin a "bounded strcpy," and the Committee has preferred to recognize existing practice rather than alter the function to better suit it to such use.


> If it was designed for non-null terminated strings, why would it specifically pad after a null terminator?

Padded and terminated strings are completely different beasts. And the text you quote tells you black on white that strncpy deals in padded strings.


“fixed-length name fields in structures such as directory entries”

“the trailing null is unnecessary for a maximum-length field”

That is a non–null terminated string.


As a c++ developer who's heard of Zig but never dived into it, I was reading this article scratching my head wondering what is it actually so unique about it.

Why the blog has a section on how it install it on the path is also very puzzling.


Zig is simple, clever and clean. certainly not perfect but it addresses much of what I disliked about c++. I wanted to like D and rust but they seem just as complex as c++. Yes, better in some ways but still full of complexity.


Sounds like a problem with poor code rather than something unique to OOP.


So more ambitiousness means you should get access to more user information?


> That's just terrible input validation and has nothing to do with setTimeout.

Except for the fact that this behaviour is surprising.

> you should be checking your input against the range that's valid. Your sample code simply doesn't do that, and that's why there's a bug.

Indeed, so why doesn't setTimeout internally do that?


> Indeed, so why doesn't setTimeout internally do that?

Given that `setTimeout` is a part of JavaScript's ancient reptilian brain, I wouldn't be surprised it doesn't do those checks just because there's some silly compatibility requirement still lingering and no one in the committees is brave enough to make a breaking change.

(And then, what should setTimeout do if delay is NaN? Do nothing? Call immediately? Throw an exception? Personally I'd prefer it to throw, but I don't think there's any single undeniably correct answer.)

Given the trend to move away from the callbacks, I wonder why there is no `async function sleep(delay)` in the language, that would be free to sort this out nicely without having to be compatible with stuff from '90s. Or something like that.


I think it's more likely that it's just "undefined behaviour" and up to the implementers of the JavaScript engines. Given that modern browsers do limit and throttle how much you can do with setTimeout in some situations (try to use setTimeout on a page after you've switched to a VR context! More than like 120hz and it'll just.... Not run the timeout anymore, from experience with Chrome).

The browser devs have decided it's acceptable to change the behaviour of setTimeout in some situations.

https://developer.chrome.com/blog/timer-throttling-in-chrome...


> women in dysfunctional, abusive relationships are not very often provided with a smartphone and a data plan

This sounds like something which you have no evidence at all for claiming.


I knew a person who was in abusive relationships where the abuser would keep making ridiculous claims that the person was cheating on them, and made them give up having their own phone as "proof" that they wouldn't cheat.

Of course, the abuser was cheating the whole time.


They were kept without computers and internet access: https://www.bbc.com/news/world-europe-19711022

So it does happen, contrary to what you claim.


I don't have evidence but I do have experience on this.

I'm not sure why you would be the quickly dismissive of something that would seem obvious to many.


I mean, it’s a ‘water is wet’ kind of statement. Prisoners aren’t provided a mobile phone and data plan either.


> “League of Legends” is caught in the middle of a dispute between Hollywood’s actors union and an audio company that provides voiceover services

How is that related to this engineering post? I wish HN took action against people commenting wildy unrelated topics.


How is it not relevant to a post by Riot/LoL?


I imagine they also "discriminate" on skills and previous jobs you have too..


Why would anyone want that? Everyone would just quote a lot wider to make up for the potential volatility of the next minute, probably leading to worse trades for retail orders.


Article: Here's a tutorial for a simple malloc

HN commenter: adjusts glasses heh, this malloc code is pathetic, here's a paper on how to write a true malloc.


Except, this seems to be no ordinary HN commenter. If I didn't know better, I'd say that the username seems to be that of Poul-Henning Kamp.


Yes, I am the author of that paper and the "phkmalloc" it describes.


glasses adjusting intensifies


Not sure how that changes anything lol. The point still stands that the original comment is needlessly rude.


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

Search: