Struct on on x86_64 mac os x

Mark Dickinson dickinsm at gmail.com
Wed Oct 21 04:18:32 EDT 2009


On Oct 20, 10:51 pm, Tommy Grav <tg... at pha.jhu.edu> wrote:
> 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?

As others have said, it depends on the platform.  But on OS X 10.6,
and on most 64-bit Linuxes that I've met, I'm fairly sure that
sizeof(long int) == sizeof(double) == 8.  In contrast, 64-bit
Windows on the same hardware will probably have sizeof(long int) == 4.

>
>      def read_header(cls):
>          hdrData = "84s"*3
>          constNData = "6s"*400

I'm confused:  why is this not "400s"*6 rather than "6s"*400?
Doesn't constName[400][6] mean 6 lots of constName[400]?
Similarly for "84s"*3.  This might be making a difference to
the padding.

[...]

--
Mark



More information about the Python-list mailing list