Mail Archives: djgpp/2002/02/15/00:30:35
X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f
|
From: | "Alvin Lau" <alvin_lau AT yahoo DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Structure size problem
|
Date: | Fri, 15 Feb 2002 13:27:31 +0800
|
Organization: | IMS Netvigator
|
Lines: | 50
|
Message-ID: | <a4i5k8$j4d51@imsp212.netvigator.com>
|
NNTP-Posting-Host: | pcd361061.netvigator.com
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.50.4807.1700
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4807.1700
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Here is my program:
#include <stdio.h>
typedef unsigned char byte;
typedef unsigned long dword;
struct tagKFName2 {
dword Index;
byte KFType;
char KFName[30];
};
struct tagKFName {
byte unknown[5];
char KFName[30];
};
typedef struct tagKFName KFNAME;
typedef struct tagKFName2 KFNAME2;
int main()
{
KFNAME buf;
KFNAME2 buf2;
printf("Size KFNAME: %d\n\nSize KFNAME2:
%d\n",sizeof(KFNAME),sizeof(KFNAME2));
printf("Index: %d\nKFType: %d\nKFName:
%d\n",sizeof(buf2.Index),sizeof(buf2.KFType),sizeof(buf2.KFName));
return 0;
}
After running this program, I got the output as follow:
Size KFNAME: 35
Size KFNAME2: 36
Index: 4
KFType: 1
KFName: 30
Obviously there have a problem about the structure size in KFNAME2, this
structure has three members (Index,KFType,KFName). According the output of
this program, the size of Index is 4, KFType is 1, KFName is 30. Then 4+1+30
should be 35, but the total size of KFNAME2 is 36. So, I want to ask some
questions:
Is this a bug in DJGPP ?
How to solve this problem ?
- Raw text -