View mode: basic / threaded / horizontal-split · Log in · Help
February 24, 2012
Re: Cannot cast void* to arrays..?
On 2/24/12, simendsjo <simendsjo@gmail.com> wrote:
> I don't get it. This gives me a dynamic array, not a static:
>      char[1] a;
>      auto b = cast(void*)a;
>      auto c = (cast(char*)b)[0..1];
>      c.length = 10; // auch!
>

You can do:
char[1] c = (cast(char*)b)[0..1];
February 24, 2012
Re: Cannot cast void* to arrays..?
On Fri, 24 Feb 2012 21:36:21 +0100, Andrej Mitrovic  
<andrej.mitrovich@gmail.com> wrote:

> On 2/24/12, simendsjo <simendsjo@gmail.com> wrote:
>> I don't get it. This gives me a dynamic array, not a static:
>>      char[1] a;
>>      auto b = cast(void*)a;
>>      auto c = (cast(char*)b)[0..1];
>>      c.length = 10; // auch!
>>
>
> You can do:
> char[1] c = (cast(char*)b)[0..1];

Thanks! I had to do an explicit cast(char[1]) (or actually char[1][1] in  
my case.)
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home