Mail Archives: djgpp/2002/02/15/03:21:25
X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f
|
Message-ID: | <3C6CBC6F.BF7EDD98@yahoo.com>
|
From: | CBFalconer <cbfalconer AT yahoo DOT com>
|
Organization: | Ched Research
|
X-Mailer: | Mozilla 4.75 [en] (Win98; U)
|
X-Accept-Language: | en
|
MIME-Version: | 1.0
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Structure size problem
|
References: | <a4i5k8$j4d51 AT imsp212 DOT netvigator DOT com>
|
Lines: | 57
|
Date: | Fri, 15 Feb 2002 07:53:24 GMT
|
NNTP-Posting-Host: | 12.90.167.184
|
X-Complaints-To: | abuse AT worldnet DOT att DOT net
|
X-Trace: | bgtnsc04-news.ops.worldnet.att.net 1013759604 12.90.167.184 (Fri, 15 Feb 2002 07:53:24 GMT)
|
NNTP-Posting-Date: | Fri, 15 Feb 2002 07:53:24 GMT
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Alvin Lau wrote:
>
> 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 ?
This is a FAQ. Hunt down the C faq. gcc is absolutely right.
--
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT XXXXworldnet DOT att DOT net)
Available for consulting/temporary embedded and systems.
(Remove "XXXX" from reply address. yahoo works unmodified)
mailto:uce AT ftc DOT gov (for spambots to harvest)
- Raw text -