4 ms·
Maybe C will finally get slices.
by hgs3 2y ago
Maybe C will finally get slices.
- flohofwoe 2y agoSlices as language features wouldn't be needed if there's just a way to associate a size/count with a pointer. For instance: https://clang.llvm.org/docs/BoundsSafety.html https://clang.llvm.org/docs/BoundsSafety.html https://clang.llvm.org/docs/BoundsSafetyImplPlans.html https://clang.llvm.org/docs/BoundsSafetyImplPlans.html
- raverbashing 2y agoWhile this goes in the right direction, it still feel like wrapping yourself in bubble wrap for safety The true ergonomic solution are slices. Because you don't need boundary checks if you're iterating using the slice count This is definitely a helpful functionality, but it still keeps to C mentality
- flohofwoe 2y agoIf the main goal is hardening existing code bases then this Clang proposal is the right approach IMHO. I think integrating slices "properly" would touch quite a few other areas of the language, which require opinionated design decision by the committee. And committees aren't exactly known for coming up with sensible language design decisions (and looking at C++, I'm fine with the C committee being very conservative). Basically, if I want an actually "better C" for new code, I use Zig. But C is still a valid option for low-level libraries that need to work everywhere (and of course for tapping into the existing library ecosystem).
- raverbashing 2y ago> If the main goal is hardening existing code bases then this Clang proposal is the right approach IMHO. Yup, on this I agree. And I've seen efforts in adding this to existing code
- pjmlp 2y agoTo note that committee refused Dennis Ritchie proposal for slices, without ever doing a counterproposal, then again I hope this new principles have a change of mindset in that regard.
- pjmlp 2y agoYeah, but then again this is like SAL from VC++, and unfortunely adoption hasn't been great since 2010. At least now, in theory, WG14 is paying attention.
- Gibbon1 2y agoI'm salty that after 40 years there isn't a standard slice_t and buffer_t. Then you could have functions in the standard library like. buffer_t allocate_buffer(size_t sz); size_t append_slice(buffer_t *dest, slice_t *src);