On 8/17/16 10:38 AM, deadalnix wrote:
On Wednesday, 17 August 2016 at 14:21:32 UTC, Steven Schveighoffer wrote:
void * is almost useless. In D you can assign a void[] from another
void[], but other than that, there's no way to write the memory or
read it.

In C, void * is also allowed to alias any other pointer. But char * is
also allowed to provide arbitrary byte reading/writing.

I'd expect that D also would provide a similar option.


Yes, but everything can alias with void*/void[] . Thus, you can cast
from void* to T* "safely".

Sure, but how do you implement, let's say, byte swapping on an integer?

ubyte[] x = &myInt[0 .. 1];
foreach(i; 0 .. x.length / 2)
   swap(x[i], x[$-i-1]);

So if the compiler can assume that x can't point at myInt, and thus myInt can't have changed, then we have a problem.

You just can't do this with void (or at least not very easily).

-Steve

Reply via email to