back
1 comments
> 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 compute sizes."

It appears to be phat pointers.

It is unclear why it has failed to catch on. One reason probably was that Microsoft decided at one point that it will not support C99 because everything should program in C++ which put a damper on the adoption of newer C features. The other reason is that compilers did not actually supported bounds checking here (I added it in GCC for UBSan in 2015) and it is still possible to lose the bound at function calls (I have patch to GCC I hope I can submit for the next version). So for a long time most people thought that VM-types were useful only for numerics.

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.