News for hackers. Stuff that matters.
Re:C’s Biggest Mistake (2009) by bsder on Saturday September 12, 2020 @08:26PM (#24457145)
> C is finished if it doesn't address the buffer overflow problem, and this proposal is a simple, easy, backwards compatible way to do it.

Is this really "simple, easy, backwards compatible"?

I think Rust kind of counterexamples this.

While Rust can throw around slices [] (effectively runtime length), throwing around [u8; 8] and [u8; 9] (compile time length) to the same function gets nasty.

Perhaps all the constexpr work in Rust will make this a lot easier.

Re:C’s Biggest Mistake (2009) by ComputerGuru on Saturday September 12, 2020 @11:58PM (#24458197)
Not constexpr, this is solved by constant generics (the famous RFC 2000) with the array bound as a constant “generic” parameter/value.

I’ve been pushing for this feature for many years and have been playing with it since it first landed in nightly. It works quite well.

Re:C’s Biggest Mistake (2009) by bsder on Sunday September 13, 2020 @12:15AM (#24458286)
Sorry, I misspoke. But this wasn't meant to be about Rust.

My point was that: if you dump slices/fat pointers into C, how does it help?

Slices/fat pointers and the corresponding checks are a runtime thing, and that's absolutely anathema to a lot of C programmers. If it's not anathema to the C programmer, they probably aren't in C anyway.

So, now you need a way so that compiled slices/fat pointers mean something, and I'm not convinced that doesn't have a lot of ramifications that are being glossed over.

Re:C’s Biggest Mistake (2009) by WalterBright on Sunday September 13, 2020 @05:02PM (#24463920)
The checks can be at compile time, given how good the data flow analysis is in the compiler. The rest are at runtime, presumably coming with a compiler switch to turn them off.

Most people using D leave the checks on.

Even without the checks, however, I can vouch that implicitly carrying around the length of the array with the array pointer is a vast improvement in the clarity of the written code.