Why are void[] contents marked as having pointers?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun May 31 16:18:46 PDT 2009
Vladimir Panteleev wrote:
> On Mon, 01 Jun 2009 00:00:45 +0300, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
>
>> const(ubyte)[] getRepresentation(T)(T[] data)
>> {
>> return cast(typeof(return)) data;
>> }
>
> This is functionally equivalent to (forgive the D1):
> ubyte[] getRepresentation(void[] data)
> {
> return cast(ubyte[]) data;
> }
> Since no allocation is done in this case, the use of void[] is safe, and it doesn't instantiate a version of the function for every type you call it with. I remarked about this in my other reply.
>
This is not safe because you can change the data.
Andrei
More information about the Digitalmars-d
mailing list