←back to thread

Thomas E. Kurtz has died

(computerhistory.org)
618 points 1986 | 2 comments | | HN request time: 0.404s | source
Show context
WalterBright ◴[] No.42150808[source]
I originally learned to program with BASIC. When I was designing D, I thought back to how easy and natural string manipulation was in BASIC, and what a festering swamp of bugs it was in C.

Having strings as easy and correct in D was a major priority, and history has shown that this was a success.

P.S. Whenever I review C code, I first look at the string manipulation. The probability of finding a bug in it is near certainty. Question for the people who disagree - without looking it up, how does strncpy() deal with 0 termination?

Thank you, Thomas Kurtz!

replies(6): >>42150847 #>>42150921 #>>42151230 #>>42153040 #>>42155368 #>>42203247 #
GauntletWizard ◴[] No.42153040[source]
I'm going to give it my best guess- it will copy up to n bytes, including the null byte if present in n, but not adding a null if the nth byte isn't a null, requiring you to set the last byte to 0 manually, whether that's allocating n+1 bytes or truncating the nth.
replies(1): >>42155243 #
1. WalterBright ◴[] No.42155243[source]
Even if you're right, you said you were guessing, meaning you'd have to look it up.

To add insult to injury, snprintf does it differently.

replies(1): >>42169661 #
2. GauntletWizard ◴[] No.42169661[source]
Yes, it's the most obnoxious behavior I could think up - Which meant I was sure it was correct, but not the kind of sure I'd want to rely on.

I also refreshed myself on snprintf, and as un-ergonomic interfaces go, they did a good job with what they had... But I will gladly take my golang multiple return values, now that I have them.

    So, only when the returned value is non-negative and less than ‘n’, the string has been completely written as expected.