This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


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

Re: data alignment issues


On Thu, Aug 09, 2001 at 09:48:22AM -0600, Trenton D. Adams wrote:
> What about with unions?  When I know damn well both platforms have the
> same size for their primitive data types is it ok to copy an entire
> union to the buffer?   After all, the union will only be the size of the
> largest data type, and no alignment issues should happen right?

Im not sure i follow what you mean.

If you have a union like

union {
        char    c;
        short   s;
        long    l;
} u;

Then the structure will normaly be 4 bytes long. But what use is such
a union? You normaly have a union of structures

union {
        a_t     a;
        b_t     b;
        c_t     c:
} u;

You then have the issue of how is the compiler aligning the data of
types a_t, b_t, c_t? 

Also, the C standard says "A union type describes an overlapping
nonempty set of member objects, each of which has an optinally
specified name and possible distinct type". I cannot see anywhere
which specifies how they overlap. One compiler may overlap them at the
beginning of the memory and another could overlap them at the end
of the memory!

        Andrew


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