logoalt Hacker News

sirwhinesalottoday at 6:52 AM5 repliesview on HN

I have in the past made fun of the Linux kernel devs, supposedly some of the best C developers in the world, for not knowing how to make stringbuffer and stringview types, but to be fair to them we didn't have the consensus we have today on the topic.

You know who did have the right idea though? Dennis Ritchie, who proposed a fat pointer type for C all the way back in 1990. Would have made for a perfect addition to C99. Imagine how different the world might have been had the committee added that in.

We had a second chance with the release of the "C's greatest mistake" blog article from Walter Bright in 2007, essentially pushing for the same idea as Ritchie (slices/stringviews) but explained with much clearer language.

Alas, didn't make it to C11.

We're now in C23, still nothing. But we did get _Generic and VLAs! Party hard.


Replies

ethbr1today at 12:56 PM

> "C's greatest mistake" blog article from Walter Bright in 2007

https://digitalmars.com/articles/C-biggest-mistake.html

And because it came up in my search and the bikeshedding discussion made me chuckle, reddit on same: https://www.reddit.com/r/C_Programming/comments/90uq7c/cs_bi...

Am curious about this esoterica, if anyone can confirm/deny:

>> Speaking of [C] arrays decaying into pointers, does anyone know why this behaviour was designed in the first place?

>> It was so that B code could be compiled as C with minimal changes. The designer felt that this would encourage people to switch from B to C. In B an array declaration actually defined a pointer and an array, with the pointer initialized to point to the array's first element.

flohofwoetoday at 10:29 AM

> But we did get _Generic and VLAs! Party hard.

VLA has been demoted to an optional feature in C11 (good).

IMHO the current main problem is that the C stdlib is stuck in the K&R era and the stdlib APIs haven't even been updated to the language features added in C99 (e.g. make use of struct args and return values). A range struct (ptr/size pair) in the stdlib and new or updated string functions to use such ranges would already go a long way.

show 1 reply
anal_reactortoday at 10:26 AM

> but to be fair to them we didn't have the consensus we have today on the topic.

This is my pet peeve of teamwork. We can choose solutions A, B or C. Each has upsides and downsides. We debate for two weeks, then we choose nothing.

show 1 reply
pjmlptoday at 6:54 AM

That only goes to show where WG14 priorities are.