Earlier quoted context omitted.
The problem is that this would have one specific ABI, which probably wouldn't match many existing structs with a flexible array member at the end. Could potentially be used for new code (while requiring every user to upgrade the standard they compile with), but has the risk of not usable for modernizing old code.
You're right that bounds checked arrays do nothing at all for existing code. But they can be added incrementally to an existing code base, as a normal part of working on the code. In that aspect it's like when prototypes were added to C. Nothing changed for existing code, but prototypes are so advantageous people would retrofit existing code incrementally when doing routine maintenance.
Modernizing C arrays for greater memory safety: a case study in the Linux kernel
121–126 of 126 posts
Re: Modernizing C arrays for greater memory safety: a case study in the Linux kernel
#122Earlier quoted context omitted.
You're right that bounds checked arrays do nothing at all for existing code. But they can be added incrementally to an existing code base, as a normal part of working on the code. In that aspect it's like when prototypes were added to C. Nothing changed for existing code, but prototypes are so advantageous people would retrofit existing code incrementally when doing routine maintenance.
I presume prototypes could be added to transform much of existing code without compatibility problems (ABI nor API), which is a clear advantage compared to checked arrays. Checked arrays might worth it regardless, but it's not applicable in most of the article's use cases.
I can attest that they are.
> it's not applicable in most of the article's use cases
I don't believe that.
Re: Modernizing C arrays for greater memory safety: a case study in the Linux kernel
#123Earlier quoted context omitted.
Starting with "That's nice" is extremely flippant and is an immediate turn off to any subsequent statement. A stronger opening to discredit the [..] proposal would be to take the closing quote "We've been doing that with D for over 20 years" and point out that storing the length of an array of a certain type is a specialization to arrays of dependent typing that has been around since Howard and de Bruijn extended lam…
I didn't say D invented it, so no need to discredit it. I said D has been using it for 20 years and proves it works famously with C style pointers and arrays.
Re: Modernizing C arrays for greater memory safety: a case study in the Linux kernel
#124Earlier quoted context omitted.
Starting with "That's nice" is extremely flippant and is an immediate turn off to any subsequent statement. A stronger opening to discredit the [..] proposal would be to take the closing quote "We've been doing that with D for over 20 years" and point out that storing the length of an array of a certain type is a specialization to arrays of dependent typing that has been around since Howard and de Bruijn extended lam…
I didn't say D invented it, so no need to discredit it. I said D has been using it for 20 years and proves it works famously with C style pointers and arrays.
Re: Modernizing C arrays for greater memory safety: a case study in the Linux kernel
#125Earlier quoted context omitted.
Starting with "That's nice" is extremely flippant and is an immediate turn off to any subsequent statement. A stronger opening to discredit the [..] proposal would be to take the closing quote "We've been doing that with D for over 20 years" and point out that storing the length of an array of a certain type is a specialization to arrays of dependent typing that has been around since Howard and de Bruijn extended lam…
Fat pointers are a purely value level construct. STLC alone covers that. Non-determinism isn't really related to the lambda cube, even CoC is deterministic.
Re: Modernizing C arrays for greater memory safety: a case study in the Linux kernel
#126Earlier quoted context omitted.
We have bounds-checkable arrays already since C99: int ( p)[n] = malloc(sizeof p); (*p)[i] = 1; // run-time bounds check https://godbolt.org/z/vb8dqx1od But yes, having a type that included the bound makes sense. But I do not think using array syntax for pointers as in your proposal makes any sense. Dennis Ritchie got it right: https://www.bell-labs.com/usr/dmr/www/vararray.pdf Ritchie DM. Variable-size arrays in C.…
> We have bounds-checkable arrays already since C99 void foo(int n, int (*p)[n]) { (*p)[n] = 1; } which has failed to catch on, because it still stores the pointer and the length as two separately handled objects. > Dennis Ritchie got it right "This paper proposes to extend C by allowing pointers to adjustable arrays and arranging that the pointers contain the array bounds necessary to do subscript calculations and c…
Having said this, I fully agree with you that having a wide pointer that combines length and pointer would be a useful feature. I just think that the syntax proposed by Dennis Ritchie fits naturally into C.