Fixing C's Biggest Mistake
Hipreme
msnmancini at hotmail.com
Thu Jan 5 09:50:12 UTC 2023
On Thursday, 5 January 2023 at 09:37:18 UTC, areYouSureAboutThat
wrote:
> On Thursday, 5 January 2023 at 09:07:57 UTC, Dom DiSc wrote:
>> On Wednesday, 21 December 2022 at 19:31:22 UTC, Walter Bright
>> wrote:
>>> My proposal for C:
>>>
>>> int a[5] = { 0, 1, 2, 3, 4};
>>> int p[..] = a; // p points to 5 elements.
>>
>> I would wish you first implement this for D:
>>
>> ```d
>> uint[] x = [1,2,3]; // create a dynamic array with initial
>> size 3
>> uint[..] y = [1,2,3]; // create a static array with automatic
>> size (not possible now)
>> ```
>
> Neither proposal will get into C.
>
> One of the design goals of C, is actually to resist change (no,
> I'm no kidding).
>
> I think that is a good thing.
>
> As for D, yes, it sure is surprising the compiler cannot
> automatically size a static array by the number of arguments
> being provided to it.
>
> But I'm not a fan of this syntax [..]
>
> Everytime I see it, I think, wtf is that!
>
> It's also confusing as it uses syntax from slices [1..$]
>
> maybe I'd settle on int[T] array = [1,2,3];
>
> now, as a programmer, I already know that T is a token that
> will get automatically replaced with something meaningful.
You can't use [T] because it is reserved as user symbol and could
break D code. For instance, T can be used as a number:
```d
struct IntStaticArray(uint T)
{
int[T] data;
alias data this;
}
IntStaticArray!(5) arr;
```
The most accepted syntax for inferred length static array was
`int[$] a = [1,2,3]`. But people insists that `import
std.array:staticArray; int[] a = [1,2,3].staticArray;` is better.
So I don't know what to say.
Anyway this thread has gone quite far and is really unproductive.
So just go and fix the C biggest mistake so people can back to be
productive again.
More information about the Digitalmars-d
mailing list