CSV Data to Binary File

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 7 10:12:33 PDT 2014


On Thursday, 7 August 2014 at 16:08:01 UTC, TJB wrote:
> Thanks Marc. Not sure what to do here. I need to the binary 
> data to be exactly the number of bytes as specified by the 
> struct.

Something else: The `align(1)` on your type definition specifies 
the alignment of the entire struct, but has no effect on the 
alignment of its fields relative to the beginning. Your probably 
want this:

align(1) struct QuotesBin
{
align(1):
   int qtim;
   int bid;
   int ofr;
   int bidsiz;
   int ofrsiz;
   short mode;
   char[1] ex;
   char[4] mmid;
}

This align the struct as a whole, and all its fields at byte 
boundaries. Without the second `align(1)`, there should be a gap 
between `mode` and `ex`. Strangely enough, when I test it, 
there's none. Will have to ask...


More information about the Digitalmars-d-learn mailing list