casting and arrays..

Kirk McDonald kirklin.mcdonald at gmail.com
Sat Mar 10 16:58:59 PST 2007


Chris Warwick wrote:
> "Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message 
> news:esvhdv$261a$1 at digitalmars.com...
>> "Chris Warwick" <sp at m.me.not> wrote in message 
>> news:esvf5h$2317$1 at digitalmars.com...
>>> std.file.read(filename);
>>>
>>> returns type void[]
> 
> Ok say you have that void[] array returned from std.read.file(). Whats the 
> best way to copy a struct out from the void array? Only way i can think is 
> memcpy, or some heavy duty casting and pointers. Is there a cleaner - 
> pretier way with D?
> 
> thanks,
> 
> cw 
> 
> 

Assuming that array.length == YourStruct.sizeof, you can say
     cast(YourStruct*)array.ptr
to treat the array as the struct in-place.

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org


More information about the Digitalmars-d-learn mailing list