Date: Thu, 07 Aug 1997 14:20:13 +1100 From: Bill Currie Subject: Re: Why does sizeof give me... In-reply-to: <33E957BE.7216@geocities.com> To: spiritseeker AT geocities DOT com, djgpp AT delorie DOT com Message-id: <199708070224.OAA03759@teleng1.tait.co.nz gatekeeper.tait.co.nz> Organization: Tait Electronics Limited MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Comments: Authenticated sender is Precedence: bulk On 6 Aug 97 at 22:06, spiritseeker wrote: > Hello, hello! > > 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. > > What to do? First, change all `int's to `short' because `int' in djgpp is 32 bits instead of 16. Second, for every `member', add `__attribute__((packed))' eg struct foo { char snafu __attribute__((packed)); long bar __attribute__((packed)); } This tells gcc not to align the data types, which it does by default. Of coarse, the `attribute__((packed))' can be #defined to (say) PACKED and you can use that instead. Bill -- Leave others their otherness.