Fixing C's Biggest Mistake

Paul Backus snarwin at gmail.com
Wed Dec 21 21:42:32 UTC 2022


On Wednesday, 21 December 2022 at 19:59:58 UTC, Walter Bright 
wrote:
> 3. Help get [..] into the C Standard which will help D, too, by 
> making D easier to interface with C
>
> 4. Getting it into C means better C debugger support for D

For the record: a feature very similar to [..] was proposed for 
inclusion into C23, by Martin Uecker in section 3.4 of the paper 
"Improved Bounds Checking for Array Types" [1]. The paper was 
discussed at the June 2021 meeting of the C committee [2], and in 
that discussion, section 3.4 received the following comment:

> With regard to section 3.4, VLA's already store sizes because 
> the platform
> needs the size for arithmetic/subtraction. So you do not need 
> new syntax.

I.e., the use-case of having runtime bounds information available 
for arrays is already covered by using a pointer-to-VLA, which 
(unlike VLAs themselves) are a required feature of C23 [3]. For 
example, one can write:

     void my_func(size_t n, int (*arr)[n])

...and then use sizeof to compute the length at runtime:

     for (size_t i = 0; i < (sizeof arr / sizeof arr[0]); i++)

Of course, anyone who has used a language like D with real slices 
will understand that this is a poor substitute, but convincing 
the C committee of that may be an uphill battle.

[1] https://open-std.org/jtc1/sc22/wg14/www/docs/n2660.pdf
[2] https://open-std.org/jtc1/sc22/wg14/www/docs/n2802.pdf
[3] https://open-std.org/jtc1/sc22/wg14/www/docs/n2778.pdf


More information about the Digitalmars-d mailing list