Binary I/O for Newbie

tjb broughtj at gmail.com
Mon Feb 27 12:27:04 PST 2012


On Monday, 27 February 2012 at 19:28:07 UTC, Tobias Brandt wrote:
>> So, something like this should work:
>> [...]
>
> It really depends on how you wrote the file originally. If you
> know that it is packed, i.e. 10+32+32+32=106 bytes per record,
> then yes.
>
> If you wrote to the file with a C++ program, then I guess the
> compiler aligned the data so that the whole struct is 128 bytes
> in size. Technically, the C++ compiler is allowed to do
> anything short of changing the order of the struct fields.
>
> You could just let your C++ program print out sizeof(TaqIdx) or
> manually divide the file size by the number of records (if you
> know it) to make sure.

Just looked at my old C++ code.  And the struct looks like this:

struct TaqIdx {
   char symbol[10];
   int tdate;
   int begrec;
   int endrec;
}__attribute__((packed));

So I am guessing I want to use the align(1) as Justin suggested. 
Correct?

TJB


More information about the Digitalmars-d-learn mailing list