cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/06/22:19:58

Date: Thu, 07 Aug 1997 14:20:13 +1100
From: Bill Currie <billc AT blackmagic DOT tait DOT co DOT nz>
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
Comments: Authenticated sender is <billc AT blackmagic DOT tait DOT co DOT nz>

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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019