First Draft: cast(ref T)... as shorthand for *cast(T*)&...

Steven Schveighoffer schveiguy at gmail.com
Wed Jan 22 04:21:23 UTC 2025


On Monday, 20 January 2025 at 23:09:24 UTC, Walter Bright wrote:
> On 1/20/2025 1:07 AM, IchorDev wrote:
>> ```d
>> void[] foo = (cast(void*)&bar)[0..bar.sizeof];
>> ```
>
> I haven't really thought about that. But this also works and is 
> simpler and easier to read:
>
> ```d
> void[] foo = cast(void[])((&bar)[0 .. 1]);
> ```

You don't need the cast even (all arrays implicitly cast to 
`void[]`)

```d
void[] foo = (&bar)[0 .. 1];
```

-Steve


More information about the dip.development mailing list