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

wjoe invalid at example.com
Fri Jul 8 10:58:24 UTC 2022


Why is that ?
My understanding is that a void[] doesn't have a distinct type 
but since the length is bytes and not elements this makes me 
believe that under the hood they are byte arrays - or, rather, 
managed chunks of memory.
How's copying memory without a distinct type different from 
copying, say, an ubyte[] to an ubyte[] ?

The compiler doesn't complain about that in @safe code:

```d
@safe void copy_voidA_to_ubyteA(in void[] s) {
   ubyte[] d;
   d.length = s.length;
   d[0..$] = cast(const ubyte[])s[0..$];
}
copy_voidA_to_ubyteA([1,2,3,4]);
```

But what if I copy pointers into an ubyte[] ?
void[] are scanned by the GC but ubyte[] aren't.


More information about the Digitalmars-d-learn mailing list