Nested structs and struct.pack
ken_ar at my-deja.com
ken_ar at my-deja.com
Wed Jan 3 07:38:29 EST 2001
Hi!
I'm having problems with nested C structs and the
struct module. The size of the structs are
different for Python and C. The following
describes the problem:
// C
#include <stdio.h>
struct a
{
long a;
};
typedef struct a A;
struct b
{
A a;
char c;
};
typedef struct b B;
struct c
{
B b;
char c;
};
typedef struct c C;
int main(int argc, char* argv[])
{
printf("Type sizes\n");
printf("A : %u\n", sizeof(A));
printf("B : %u\n", sizeof(B));
printf("C : %u\n", sizeof(C));
}
// end
Here the size of C is 12.
# Python
import struct
struct.calcsize("lcc")
# end
Here the size is 8.
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 ?
With regards,
-Ken.
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list