Mail Archives: djgpp/1997/08/10/07:12:38
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!
- Raw text -