A
Anand Buddhdev
Hi everyone,
I'm a C newbie, so please be gentle. I have a program that defines the
following things:
typedef union
{
unsigned int I;
unsigned char b[4];
} dword;
/* Structure for record 0 of the DAWG. */
typedef struct
{
unsigned char magic[5];
unsigned char name[11];
unsigned char title[41];
unsigned char desc[41];
unsigned char author[41];
unsigned char extra[41];
unsigned char ch[64];
unsigned char numchars;
unsigned char catsym[8];
unsigned char catname[8][11];
unsigned char catinclude[8][8];
unsigned char numcategories;
dword numnodes;
} dawghdr;
I expect the size of the dawghdr structure to be 410 bytes. However,
on compiling this program with gcc 3.3.2 on linux, dawghdr uses 412
bytes. I've examined the memory space of this structure, and it seems
to me that 2 extra bytes appear between the numcategories and numnodes
members. Could anyone be kind enough to explain why this might be
happening?
The program writes this structure to a disk file as a record, and I
later read this output file with a python script, but the script falls
over, as it fails to read the correct value of numnodes, since it has
no way of knowing about the 2 extra bytes.
I'm a C newbie, so please be gentle. I have a program that defines the
following things:
typedef union
{
unsigned int I;
unsigned char b[4];
} dword;
/* Structure for record 0 of the DAWG. */
typedef struct
{
unsigned char magic[5];
unsigned char name[11];
unsigned char title[41];
unsigned char desc[41];
unsigned char author[41];
unsigned char extra[41];
unsigned char ch[64];
unsigned char numchars;
unsigned char catsym[8];
unsigned char catname[8][11];
unsigned char catinclude[8][8];
unsigned char numcategories;
dword numnodes;
} dawghdr;
I expect the size of the dawghdr structure to be 410 bytes. However,
on compiling this program with gcc 3.3.2 on linux, dawghdr uses 412
bytes. I've examined the memory space of this structure, and it seems
to me that 2 extra bytes appear between the numcategories and numnodes
members. Could anyone be kind enough to explain why this might be
happening?
The program writes this structure to a disk file as a record, and I
later read this output file with a python script, but the script falls
over, as it fails to read the correct value of numnodes, since it has
no way of knowing about the 2 extra bytes.