Mail Archives: djgpp/1997/08/06/22:19:58
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 -