4 ms·
It’s more complex than that in practice. You need to support variable length arrays, which means you need to pass length information with the pointer, which dou
by KerrAvon 2y ago
It’s more complex than that in practice. You need to support variable length arrays, which means you need to pass length information with the pointer, which doubles the size of array arguments. And that has ripple effects; you can’t do that indiscriminately without memory bloat and severe runtime impact, so you need to annotate argument. And you don’t have complete memory safety. And it takes a lot of manual programmer effort to get there.
This has been studied for decades; there have been many attempts to build a safer version of C. And eventually the C standard committee will have to decide on an approach or lose out to newer languages at an increasingly accelerated rate.
- nine_k 2y agoThe fun part here is that most allocators already keep the size of the chunk within the header of the chunk, before the pointer they return to the caller of malloc(3). (Yes, jemalloc does not, it keeps the size info in a different way.) BTW I mentioned this as a master's graduation project, not a realistic way forward, because, well, it's not needed. I'd say that C will lose relevance slowly, more and more, as much as Zig will gain relevance, hopefully to the point of becoming the default choice, and having key parts of Linux kernel ported to it. Not Rust, which mostly replaces C++; even though it can venture on the C territory, its not comfortable nor seamless there. Zig is so seamless, it can even compile your C code along the way. It can do gnarly stuff like handling memory-mapped control registers with relative ease, and with much fewer footguns than C. C is old, and its age shows. It needs to gradually retire, the way Fortran-77 did.
- KingLancelot 2y ago[dead]
- Koshkin 2y ago> C will lose relevance slowly, more and more, as much as Zig will gain relevance I have felt a bout of nostalgia for the years past reading this.
- n_plus_1_acc 2y agoRust always passes slices as (ptr, len), and it seems to have to runtime performance impact.
- steveklabnik 2y agoWhat impact are you thinking of?
- n_plus_1_acc 2y agoGP claimed that passing arrays as (ptr,len) would have a dramatic performance impact. I used Rust as a counterexample.
- steveklabnik 2y agoOh! I think you had a typo: “to” instead of “no.” I thought you were saying there is a performance impact. Thanks for clarifying :)
- n_plus_1_acc 2y agoI didn't notice, thanks. I agreee that made it confusing.
- n_plus_1_acc 2y ago*no runtime impact