Newsgroups: comp.os.msdos.djgpp Date: Wed, 6 Aug 1997 21:44:58 -0400 From: Insomnia Subject: Re: Why does sizeof give me... In-Reply-To: <33E957BE.7216@geocities.com> Message-ID: References: <33E957BE DOT 7216 AT geocities DOT com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII NNTP-Posting-Host: degobah.core.binghamton.edu Organization: Binghamton University Lines: 29 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Wed, 6 Aug 1997, spiritseeker wrote: > I'm converting some code from my old 16 bit c programs to > 32 bit .. suddenly sizeof gives me values that are many bytes > larger than my old structures! This means whenever i want to fread > and fwrite files the structures get's messed up! > > I compiled the same .c file in borland. and there was a 300 byte > difference beetwen the sizeof from bc and the one from djgpp. > At least part of your problem is most likely due to gcc's behavior of 32-bit alligning fields in a structure. This makes the structure significantly faster, but the storage of the structure is bit different than with Borland. To make it store elements more like you would expect, try defining your structures with the attribute packed on each element in the structure, ie: struct mystruct { char element1 __attribute__ ((packed)); int element2 __attribute__ ((packed)); ..... }; Hope this helps. Corrections/constructive criticism welcome, as are flames (I like seeing examples of people more pathetic than myself). --Insomnia --Sleep is for the weak!