What is best way to read and interpret binary files?

Stanislav Blinov stanislav.blinov at gmail.com
Tue Nov 20 12:01:49 UTC 2018


On Tuesday, 20 November 2018 at 11:54:59 UTC, welkam wrote:
> On Monday, 19 November 2018 at 22:14:25 UTC, Neia Neutuladh 
> wrote:
>>
>> Nothing stops you from writing:
>>
>>     SomeStruct myStruct;
>>     fd.rawRead((cast(ubyte*)&myStruct)[0..SomeStruct.sizeof]);
>>
>> Standard caveats about byte order and alignment.
>
> Never would I thought about casting struct to static array. If 
> I understood correctly you cast myStruct pointer to ubyte 
> pointer and then construct static array on stack with 
> tmpArray.ptr = (ubyte pointer) and tmpArray.sizeof = 
> SomeStruct.sizeof

Almost correct, except it's not a static array, it's just a 
slice, i.e. ubyte[].


More information about the Digitalmars-d-learn mailing list