X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f Message-ID: <0BA32251E589D2118EA60008C70DDCAB025F91AF@JNJFRISEXS1.eu.jnj.com> From: "Baribaud, Christophe [JNJFR]" To: "'djgpp AT delorie DOT com'" Subject: RE: Structure size problem Date: Fri, 15 Feb 2002 07:27:37 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2655.55) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C1B5E9.DC8844D0" Reply-To: djgpp AT delorie DOT com This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C1B5E9.DC8844D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable It is not a bug. In order to work efficiently, compiler aligns datas, since processor accesses them using a 16 bit or 32 bit data bus. So, KFType is implemented as a 16 bit word, and 8 bits of memory are = "lost" To modify alignment, use .align directive Regards -----Message d'origine----- De : Alvin Lau [mailto:alvin_lau AT yahoo DOT com] Envoy=E9 : vendredi 15 f=E9vrier 2002 06:28 =C0 : djgpp AT delorie DOT com Objet : Structure size problem Here is my program: #include 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 ? ------_=_NextPart_001_01C1B5E9.DC8844D0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable RE: Structure size problem

It is not a bug.
In order to work efficiently, compiler aligns datas, = since processor accesses them using a 16 bit or 32 bit data bus.
So, KFType is implemented as a 16 bit word, and 8 = bits of memory are "lost"

To modify alignment, use .align directive

Regards

-----Message d'origine-----
De : Alvin Lau [mailto:alvin_lau AT yahoo DOT com]
Envoy=E9 : vendredi 15 f=E9vrier 2002 06:28
=C0 : djgpp AT delorie DOT com
Objet : Structure size problem


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.K= FName));

  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 ?


------_=_NextPart_001_01C1B5E9.DC8844D0--