On Tue, Mar 30, 2021 at 12:32:36AM +, mw via Digitalmars-d-learn wrote:
> On Monday, 19 November 2018 at 22:32:55 UTC, H. S. Teoh wrote:
> > Actually, the case is unnecessary, because arrays implicitly convert
> > to void[], and pointers are sliceable. So all you need is:
> >
> >
On Monday, 19 November 2018 at 22:32:55 UTC, H. S. Teoh wrote:
Actually, the case is unnecessary, because arrays implicitly
convert to void[], and pointers are sliceable. So all you need
is:
SomeStruct myStruct;
fd.rawRead(()[0 .. 1]);
This works for all POD types.
Writing
On Tuesday, 20 November 2018 at 12:01:49 UTC, Stanislav Blinov
wrote:
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;
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*))[0..SomeStruct.sizeof]);
Standard caveats about byte order and alignment.
On Monday, 19 November 2018 at 22:14:25 UTC, Neia Neutuladh wrote:
Nothing stops you from writing:
SomeStruct myStruct;
fd.rawRead((cast(ubyte*))[0..SomeStruct.sizeof]);
Standard caveats about byte order and alignment.
Never would I thought about casting struct to static array. If I
On Mon, 19 Nov 2018 14:32:55 -0800, H. S. Teoh wrote:
>> Standard caveats about byte order and alignment.
>
> Alignment shouldn't be a problem, since local variables should already
> be properly aligned.
Right, and the IO layer probably doesn't need to read to aligned memory
anyway.
Struct
On Mon, Nov 19, 2018 at 10:14:25PM +, Neia Neutuladh via
Digitalmars-d-learn wrote:
> On Mon, 19 Nov 2018 21:30:36 +, welkam wrote:
> > So my question is in subject/title. I want to parse binary file into D
> > structs and cant really find any good way of doing it. What I try to do
> >
On Mon, 19 Nov 2018 21:30:36 +, welkam wrote:
> So my question is in subject/title. I want to parse binary file into D
> structs and cant really find any good way of doing it. What I try to do
> now is something like this
>
> byte[4] fake_integer;
> auto fd = File("binary.data", "r");
>
So my question is in subject/title. I want to parse binary file
into D structs and cant really find any good way of doing it.
What I try to do now is something like this
byte[4] fake_integer;
auto fd = File("binary.data", "r");
fd.rawRead(fake_integer);
int real_integer = *(cast(int*)