←back to thread

71 points susam | 6 comments | | HN request time: 1.112s | source | bottom
1. rini17 ◴[] No.43673982[source]
Heh so it seems because the Pascal arrays and strings were so atrocious, Mr.Kernighan avoided them completely in C. Everyone is supposed to roll their own, with quite disastrous consequences.
replies(3): >>43674095 #>>43676614 #>>43676661 #
2. WalterBright ◴[] No.43674095[source]
Everyone tries to roll their own strings in C, and eventually give it up, because the 0-terminated strings are so deeply embedded in the language and the library.

Even D still has a nod to C strings in it, in that string literals like "abc" have a 0 appended to them that is not included in the array length. "abc" can implicitly convert to a char*, which makes it very convenient when calling printf.

replies(1): >>43674475 #
3. duskwuff ◴[] No.43674475[source]
On the other hand: having your standard string type limited to 255 characters - requiring a completely different set of functions to manipulate longer ones - is painful in its own way.

(You can avoid some of the pain by using a big-endian length, and converting immutable Str64K pointers to Str255 by taking a pointer to the second byte of the length. But that's a terrible hack.)

replies(1): >>43674537 #
4. pjmlp ◴[] No.43674537{3}[source]
Only if stuck in standard Pascal, as Pascal evolution, Modula-2 had already fixed that by 1978.

Whereas by the time Turbo Pascal for Windows came to be, that was also sorted out in Object Pascal according to Borland linage.

As evolution to Modula-2, following up on Pascal evolution, Oberon had it sorted out as well in 1990.

5. dtgriscom ◴[] No.43676614[source]
I was using Pascal to program Mac apps in the late '80s. I was forever finding myself wanting a string, but having an array of characters. What a pain.
6. int_19h ◴[] No.43676661[source]
The problem of the original standard Pascal is that you couldn't roll your own strings in it, because it didn't have pointer arithmetics or heap-allocated variable-length arrays, at all.