Mail Archives: djgpp/2001/04/18/08:32:10
On 18 Apr 2001, at 13:35, Waldemar Schultz wrote:
> Eli Zaretskii schrieb:
> >
> > On Wed, 18 Apr 2001, Waldemar Schultz wrote:
> >
> > > BTW I couldn't resist to try the `-fpack-struct' switch Eli mentioned:
> > > now MINGW reports the size of the struct being _97_ vs _88_ without the
> > > switch.
> >
> > That sounds like a bug in MinGW. What version of GCC is that? Is the
> > version of GCC you use for DJGPP compilation different?
>
> MINGW>gcc -v
> Reading specs from
> E:\MINGW\BIN\..\lib\gcc-lib\i386-mingw32msvc\2.95.2\specs
> gcc version 2.95.2 19991024 (release)
>
> DJGPP>gcc -v
> Reading specs from e:/djgpp/lib/gcc-lib/djgpp/2.952/specs
> gcc version 2.95.2 19991024 (release)
>
-fpack-struct seems to be broken with gcc-2.95.X for DJGPP.
I tested following short test program:
#include <iostream>
struct foo { char foo_1;
short foo_2;
long foo_3;
double foo_4; } ;
foo x;
#define _offset_(a) (((char *) &x.a) - ((char *) &x.foo_1))
int main (void) { std::cout << sizeof(foo) << " ("
<< _offset_(foo_1) << " "
<< _offset_(foo_2) << " "
<< _offset_(foo_3) << " "
<< _offset_(foo_4)
<< ")\n"; }
Here is output I got:
gcc-2.95.3 for DJGPP: 16 (0 2 4 8)
gcc-2.95.2 DJGPP to MINGW cross-compiler: 15 (0 1 3 7)
gcc-3.0 20010314 (prerelease) for DJGPP: 15 (0 1 3 7)
I didn't test other versions.
My suggestion: put
#pragma pack()
before definition of structure
and
#pragma pack(1)
after it. I'm using it already for a long time without problems (except
early prereleases of gcc-2.95 where #pragma pack() was buggy).
This is better way than -fpack-struct as it's only packs structures one
wants to pack.
Andris
- Raw text -