From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: Why does sizeof give me... Date: Wed, 06 Aug 1997 22:17:00 -0400 Organization: Cornell University http://www.cornell.edu Lines: 64 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <33E9301B.AC3@cornell.edu> References: <33E957BE DOT 7216 AT geocities DOT com> Reply-To: asu1 AT cornell DOT edu NNTP-Posting-Host: cu-dialup-0038.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Insomnia wrote: > > At least part of your problem is most likely due to gcc's > behavior of 32-bit alligning fields in a structure. that is correct but a large part should be because int's are 32 bit rather than 16. > struct mystruct { > char element1 __attribute__ ((packed)); > int element2 __attribute__ ((packed)); > ..... > }; > Hope this helps. Corrections/constructive criticism welcome, > as are flames not a flame. in declaring structs as packed, you do not have to apply the attribute to each element of the struct, you can apply it to the struct as a whole: #include #include int main(void) { typedef struct a { short x; int y; } a; struct p { short x; int y; } __attribute__((packed)) p; printf("%lu\n", sizeof(a)); printf("%lu\n", sizeof(p)); return 0; } output: D:\djgpp\C>test 8 6 -- Sinan ******************************************************************* A. Sinan Unur WWWWWW |--O+O mailto:sinan DOT unur AT cornell DOT edu C ^ http://www.people.cornell.edu/pages/asu1/ \ ~/ Unsolicited e-mail is _not_ welcome, and will be billed for. *******************************************************************