digitalmars.D.learn - rawWrite of a struct suggestions
- Charles Hixson via Digitalmars-d-learn (17/17) Mar 25 2016 I've got a simple struct:
- Adam D. Ruppe (3/4) Mar 25 2016 rawWrite takes a generic array of anything... you should be able
- Charles Hixson via Digitalmars-d-learn (3/7) Mar 25 2016 Thanks, that compiled. It's running a test now...and I'm leaving it for...
- Charles Hixson via Digitalmars-d-learn (4/13) Mar 26 2016 OK, after removing a few bugs, preliminary checks say that this works
I've got a simple struct: struct Chnk { ulong id; char[20] wrd; ubyte length; ... <--various utility functions and constructors } That I'm trying to write to a file. I want to use an unformatted read/write because I want this to be a random access file. But when I try to cast a Chnk to a ubyte[], I get an error, and when I try to to!ubyte[] it I get a slightly different error:: Error: template instance isRawStaticArray!() does not match template declaration isRawStaticArray(T, A...) I don't want to copy it twice each time I read or write it, as I would if, e.g., I used OutBuffer. How should I approach this? Do I need to use fread/fwrite? I'm sure I used to be able to pass a pointer and length, but I can't find that option anymore.
Mar 25 2016
On Friday, 25 March 2016 at 18:25:28 UTC, Charles Hixson wrote:But when I try to cast a Chnk to a ubyte[], I get an error, andrawWrite takes a generic array of anything... you should be able to rawWrite((&your_object)[0 .. 1])
Mar 25 2016
On 03/25/2016 11:32 AM, Adam D. Ruppe via Digitalmars-d-learn wrote:On Friday, 25 March 2016 at 18:25:28 UTC, Charles Hixson wrote:Thanks, that compiled. It's running a test now...and I'm leaving it for a few hours.But when I try to cast a Chnk to a ubyte[], I get an error, andrawWrite takes a generic array of anything... you should be able to rawWrite((&your_object)[0 .. 1])
Mar 25 2016
OK, after removing a few bugs, preliminary checks say that this works perfectly. Thanks again, as I never would have even considered that approach. On 03/25/2016 12:24 PM, Charles Hixson via Digitalmars-d-learn wrote:On 03/25/2016 11:32 AM, Adam D. Ruppe via Digitalmars-d-learn wrote:On Friday, 25 March 2016 at 18:25:28 UTC, Charles Hixson wrote:Thanks, that compiled. It's running a test now...and I'm leaving it for a few hours.But when I try to cast a Chnk to a ubyte[], I get an error, andrawWrite takes a generic array of anything... you should be able to rawWrite((&your_object)[0 .. 1])
Mar 26 2016