This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Weird structure alignment on GCC 4.2


Hi All,

I tried to browse the mailing list about that, but there are so many
threads that I gave up, so I end up asking you the question:
What I need is that for obvious reasons 32 bits element are considered
as Words and aligned on 32bits addresses, 16bits elements are as
considered Half-Words and aligned on 16bits addresses and 8bits
elements are considered as Bytes and aligned on 8bits addresses which
was fine with all previous version of GCC I was using. I have defined
some structure like that:

struct _s1 {
    unsigned char e1;
    unsigned char e2;
};

struct _s2 {
    void e1;
    struct _s2 e2[2];
    void e3;
};


The result is that with no packing attribute, the line "struct _s2
e2[2];" will be interpreted as ".align 4 / .byte / .byte .align 4 /
.byte / .byte" however there is absolutely no reason why this
alignment in the middle of the structure happens. The problem when
using the "packed" attribute is that most of the 16bits elements will
be considered as 2 8bits elements and 32 bits elements will be
considered as 4 8bits elements which is absolutely not what I want as
these structures are mapped on internal registers that must be written
in an atomic instruction.

So the question is, what did I miss ? Is it the intended behavior for
GCC >= 4.2 or does a patch already exist for fixing that.

Thanks a lot,
--
ender


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