From: DavMac AT iname DOT com (Davin McCall) Newsgroups: comp.os.msdos.djgpp Subject: Re: Generous SIZEOF Date: Sun, 12 Sep 1999 13:49:27 GMT Organization: Monash Uni Lines: 49 Distribution: world Message-ID: <37dbad8f.30594879@newsserver.cc.monash.edu.au> References: NNTP-Posting-Host: damcc5.halls.monash.edu.au X-Trace: towncrier.cc.monash.edu.au 937144164 22898 130.194.198.138 (12 Sep 1999 13:49:24 GMT) X-Complaints-To: abuse AT monash DOT edu DOT au NNTP-Posting-Date: 12 Sep 1999 13:49:24 GMT X-Newsreader: Forte Free Agent 1.1/32.230 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com The compiler is rounding up the size of the structure to the nearest four byte boundary, so that accesses are more efficient (particularly when using an array of structures). If you want to prevent this, declare the structure with attribute packed eg: struct CD { char Title[100]; char Interpreter[100]; int Year; char Live; } __attribute__((packed)); struct CD All[MAX]; Davin. On Sun, 12 Sep 1999 13:21:24 +0200, Michael Uplawski wrote: >Hi. > >Why is djgpp (or any compiler) adding 3 bytes of memory, if the sum of >memory used by a struct is 205 Bytes? >Okay, as my English is not good enough to describe it completely, here >is my example: >------------------- >#define MAX 450 > >struct CD >{ > char Title[100]; > char Interpreter[100]; > int Year; > char Live; >} All[MAX]; >-------------------- > >The sum of memory used by each variable is 205 Bytes on a >32bit-system, right? If I use SIZEOF with a pointer to an element of >the array (or whatever the correct terminology might be, my K&R is in >German), 208 Bytes are reported. __________________________________________________________ *** davmac - sharkin'!! davmac AT iname DOT com *** my programming page: http://yoyo.cc.monash.edu.au/~davmac/