Cannot cast void* to arrays..?

simendsjo simendsjo at gmail.com
Fri Feb 24 11:44:40 PST 2012


On Fri, 24 Feb 2012 20:42:20 +0100, Justin Whear  
<justin at economicmodeling.com> wrote:

> On Fri, 24 Feb 2012 20:34:19 +0100, simendsjo wrote:
>
>> char[] a;
>>      auto b = cast(void*)a;
>>      auto c = cast(char[])b; // Error: e2ir: cannot cast b of type void*
>>      to
>> type char[]
>
> Arrays have a length--you need to cast the pointer to a char*, then slice
> it.

Ah, of course, thanks.
But what about static arrays?
     char[1] a;
     //a.length = 10; // constant a.length is not an lvalue
     auto b = cast(void*)a;
     auto c = cast(char[1])b; // Error: e2ir: cannot cast b of type void*  
to type char[1LU]


More information about the Digitalmars-d-learn mailing list