Fixing C's Biggest Mistake
max haughton
maxhaton at gmail.com
Wed Jan 4 03:13:25 UTC 2023
On Wednesday, 4 January 2023 at 03:04:31 UTC, areYouSureAboutThat
wrote:
> On Wednesday, 21 December 2022 at 19:09:37 UTC, Walter Bright
> wrote:
>> https://news.ycombinator.com/edit?id=34084894
>>
>> I'm wondering. Should I just go ahead and implement [..] in
>> ImportC?
>
> I'd much rather see @attributes strategically' incorporated
> into D's betterC.
>
> e.g.
>
> module test;
>
> extern(C) void main()
> {
> import core.stdc.stdio : printf;
>
> // Accesses to this array will be bounds checked at
> runtime.
> @checked int[5] arr = [ 0, 1, 2, 3, 4];
>
> for (int i = 0; i < 10; i++) // runtime will catch this
> error.
> {
> printf("%d\n", arr[i]);
> }
>
> }
>
This is already caught by the runtime. The idea of betterC is
that you are opting into these checks.
More information about the Digitalmars-d
mailing list