Why are void[] contents marked as having pointers?

Vladimir Panteleev thecybershadow at gmail.com
Mon Jun 1 04:12:40 PDT 2009


On Mon, 01 Jun 2009 02:18:46 +0300, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:

> 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.
>>

Which is why I wrote "forgive the D1" :)
I've yet to switch to D2, but it's obvious that the const should be there to ensure safety.

-- 
Best regards,
 Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list