[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] struct align



Hi,

I've found this thing while coding some stuff:

#include <stdio.h>

struct
{
        char x;
        short y;
        char v;
        long z;
        char u;
} a;

int main(void)
{
        printf( "%p %p %p %p %p %d\n", &a.x, &a.y, &a.v, &a.z, &a.u, sizeof(a) );
        return 0;
}

when I run this on Atari with the newest gcc (and vbcc as well), I've got:

0x1e43d58 0x1e43d5a 0x1e43d5c 0x1e43d5e 0x1e43d62 12 for vbcc
and
0x1e58988 0x1e5898a 0x1e5898c 0x1e5898e 0x1e58992 12 for gcc

But on linux gcc:

0x80495b8 0x80495ba 0x80495bc 0x80495c0 0x80495c4 16

You see -- the 3rd member is put xxxxxC address (i.e. divisible by 4), fine. But now, on both atari compilers is then 'long' member aligned on 2 bytes (xxxxE, which is 14 for x = 0, i.e. divisible only by 2) what I find wrong since it should work according to the data type (char = aligned on 1 byte boundary, short = 2 bytes, long = 4 bytes, ...) and this assumption supports the fact it works in that way on linux's gcc. But I have no idea, what's wrong here? linker setup or gcc setup?

--
MiKRO / Mystic Bytes
http://mikro.atari.org