Fixing C's Biggest Mistake

Ki Rill rill.ki at yahoo.com
Fri Jan 20 15:41:20 UTC 2023


On Friday, 6 January 2023 at 13:43:33 UTC, Patrick Schluter wrote:
> On Thursday, 5 January 2023 at 23:09:43 UTC, H. S. Teoh wrote:
>> On Thu, Jan 05, 2023 at 10:35:37PM +0000, areYouSureAboutThat 
>> via Digitalmars-d wrote: [...]
>>> to be honest, I've never needed a static array in D.
>>
>> :-D  I haven't really used static arrays very much myself, but 
>> occasionally they're useful.  E.g. in one project where I use 
>> a lot of 4-element int arrays, using static arrays for them 
>> reduces a lot of GC pressure, and also gives me nice by-value 
>> semantics (useful in certain contexts).
>>
>>
>> [...]
>>
> The annoying and shameful thing about this static array size 
> auto-determination is that it is a feature that even K&R C was 
> able to provide. We will probably see men on the Moon again 
> before D is able to do it ;-)

It has been implemented:

```d

scope int[] arr = [10, 20, 30];

```

In my opinion, it's a much better design than this:

```d

int[$]    arr = [10, 20, 30];
int[..]   arr = [10, 20, 30];
int[auto] arr = [10, 20, 30];

```

Link: 
https://dlang.org/changelog/pending.html#dmd.scope-array-on-stack


More information about the Digitalmars-d mailing list