This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: -fpack-struct


This may be more fallout of the 'pragma pack' thing from early October.
>From the hip, I'm going to say that looking through the ChangeLogs in
that time from Nickc (and to a much lesser extent, myself) might be wise
for the person to debug this.

Randy Joiner wrote:

> Unixware hasn't a problem, takes a float/char/float/char struct and
> compacts it to 12 bytes, as does hand optimization, but I can't get egcs
> to do it.  It'll give me sizeof=16 everytime.  
> -fpack-struct doesn't give me any problems or errors, but I apparently
> can't get it to work.

Please include testcases (don't assume that we'll write the same 6 line
test program you wrote) as well as full target triplets when asking for
help.   I [ think I] know what target you're on, but others won't.


First, I created a testcase:

#include <stddef.h>

#if PACK
#pragma pack(2)
#endif

struct foo
{
        float   blah;
        char    bletch;
        float   wretch;
        char    blerf;
} foo;


int
main()
{
        printf("struct size %d\n", sizeof(foo));
        printf("Offsets: blah %d, bletch %d, wretch, %d, blerf %d\n",
                offsetof(struct foo, blah),
                offsetof(struct foo, bletch),
                offsetof(struct foo, wretch),
                offsetof(struct foo, blerf)
                );
}



Then, I magically intuited the flags you were passing to the UW compiler
to get a 12-byte struct.


$ cc  -Zp2 /tmp/r.c -o /tmp/r && /tmp/r
struct size 12
Offsets: blah 0, bletch 4, wretch, 6, blerf 10


Then I verified that EGCS (i686-pc-udk which is very close strain of
your UW compiler)of the moment doesn't pack them:

$ ./xgcc   -B./   -fpacked-structs /tmp/r.c -o /tmp/r && /tmp/r
struct size 16
Offsets: blah 0, bletch 4, wretch, 8, blerf 12

Then I verified my crafty work around did pack them the same:

$ ./xgcc   -DPACK -B./   -fpacked-structs /tmp/r.c -o /tmp/r && /tmp/r
struct size 12
Offsets: blah 0, bletch 4, wretch, 6, blerf 10


My guess is that it won't be terribly hard to debug, (nice small
testcase, easy failure mode, etc.) but I won't have time to look at it
until early December.    

RJL


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]