Struct on on x86_64 mac os x
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Oct 20 23:23:19 EDT 2009
En Tue, 20 Oct 2009 18:51:21 -0300, Tommy Grav <tgrav at pha.jhu.edu>
escribió:
> I have created a binary file that saves this struct from some C code:
>
> struct recOneData {
> char label[3][84];
> char constName[400][6];
> double timeData[3];
> long int numConst;
> double AU;
> double EMRAT;
> long int coeffPtr[12][3];
> long int DENUM;
> long int libratPtr[3];
> };
>
> I try to read this file with python (ActiveState 2.6.3 on x86_64 Mac OS
> X 10.6.1) using the
> code below the hdrData and constNData are fine, while from the timeData
> onwards there
> are obvious problems. The code below works fine for a 32bit binary read
> with i386 python
> 2.5.2. Does anyone know what the proper format of a C double and long
> int is for a x86_64
> binary?
I'd start comparing at least both struct sizes to see if they match. Then,
at the C side determine offset and size of each member using macros like
these:
#define COUNT_OF(_array) (sizeof(_array)/sizeof(*(_array)))
#define OFFSET_OF(_structure, _member) ((size_t)&(((_structure
*)0)->_member))
#define SIZE_OF(_structure, _member) (sizeof((((_structure *)0)->_member)))
and then add padding bytes ('x') to the struct definition in Python to
match those offsets (and probably use '=' for standard sizes).
--
Gabriel Genellina
More information about the Python-list
mailing list