Cannot copy void[] to void[] in @safe code?

wjoe invalid at example.com
Fri Jul 8 12:55:39 UTC 2022


On Friday, 8 July 2022 at 12:26:03 UTC, ag0aep6g wrote:
> You're allowed to copy from `ubyte[]` to `ubyte[]`. But you're 
> not allowed to copy from `ubyte[]` to `int*[]`, because 
> reinterpreting a bunch of bytes as pointers is not safe.
>
> The thing about `void[]` is that it can point to memory that 
> also has a typed alias. You can have a `void[]` and a `ubyte[]` 
> pointing to the same memory. And you can have a `void[]` and an 
> `int*[]` pointing to the same memory. So if you were allowed to 
> copy from `void[]` to `void[]`, you'd practically be allowed to 
> copy from `ubyte[]` to `int*[]`. But that's not safe.
>
That makes a lot of sense. Thanks!



More information about the Digitalmars-d-learn mailing list