Re: structure size and structure element offset calculation issue

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

 



On Fri, May 23, 2014 at 6:51 AM, Sivaprasad
<sivaprasad.pv@xxxxxxxxxxxxxxxxxx> wrote:
> On our custom processor there is no constraint for short type variable to
> align at 4 byte address, then how to resolve this issue.

The fact that you don't need to align a short on a 2-byte boundary is
why struct { short s; } is aligned on a 2-byte boundary.  However,
struct { int i; short s; } has an int field, which I assume must be
aligned on a 4-byte boundary.  Therefore the whole struct must be
aligned on a 4-byte boundary.  Therefore, in order to make arrays of
the struct work correctly, the size of the struct is aligned to a
4-byte boundary.


> Is there any compiler option available ?

-fpack-struct

Be sure to read the warning in the docs.

Ian




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux