Struct on on x86_64 mac os x

Ulrich Eckhardt eckhardt at
Wed Oct 21 09:41:39 CEST 2009

Tommy Grav 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];
>       };

The sizes of integers and floating-point numbers vary between different
systems. Further, floating point layout and endianess also vary between
systems. If you want to define a file format, you can't simply write a C
struct to disk.

1. Use JSON or XML or any other text-based metaformat to build your format
2. Otherwise, make up your mind byte by byte how the things should look on
disk. That includes things like whether 'DENUM' is 2, 3, 5 or 42 bytes
large and which byte comes first. You can then write code to write the
structure to disk in that format, both in C and in Python. For the C part,
also take a look at <stdint.h>, which contains useful aliases for integers
with a well-defined size.


Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

More information about the Python-list mailing list