Nested structs and struct.pack
Duncan Booth
duncan at rcp.co.uk
Wed Jan 3 08:51:29 EST 2001
ken_ar at my-deja.com wrote in <92v6g5$t87$1 at nnrp1.deja.com>:
>I've probably misunderstood how the compiler lays
>out nested structs. But is there any way to tell
>the struct module that I have nested structs so
>that the C compiler and Python produce the same
>result ?
>
You can use pad bytes ('x' in the format string). So instead of a format of
"lcc" you could use "lcxxxcxxx" if your machine is little endian, or
"lxxxcxxxc" if it is big endian.
Of course you will have to know exactly how the struct is laid out in
memory and this will vary between machines, compilers, or even with
different options given to the same compiler.
More information about the Python-list
mailing list