struct to byte[]

BCS BCS at pathlink.com
Wed Dec 13 20:48:43 PST 2006


Derek Parnell wrote:
> 
> 
> Yes, but unfortunately the actual function is faulty. Here is what I had to
> do to get it to work ...
> 
> ubyte [] toByteArray (T) (inout T t)
> {
>     union ubyte_abi
>     {
>         ubyte[] x;
>         struct
>         {
>            uint  xl; // length
>            void* xp; // ptr
>         }
>     }
>     ubyte_abi res;
>     res.xp = cast(void*)&t;
>     res.xl = T.sizeof;
>     return res.x;
> }
> 

What didn't work???
Unless arrays are broken, that should be the same.;



More information about the Digitalmars-d mailing list