[Issue 18580] std.conv.to!(ubyte[])(void[]) should work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 9 17:18:21 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18580

--- Comment #7 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
Going from void[] to anything is the safety problem, because that's when the
data would potentially be reintrepreted incorrectly. Going to void[] from
anything doesn't directly introduce @safety problems. It just strips out the
ability to prevent them once converting to something else, because the type
information has been lost. I believe that the normal thing to do with void[] is
do something like write to a file or socket, in which case, it's arguably just
an @safe way to convert arbitrary data to bytes rather than require an explicit
cast (since the C API uses void* IIRC).

Either way, if you have void[] and are looking to do something with it other
than hand it off to a C API that takes void* and writes bytes to some system
resource, you need to know where it comes from and verify that the cast that
you're doing is @safe.

--


More information about the Digitalmars-d-bugs mailing list