structure size and structure element offset calculation issue

Sivaprasad sivaprasad.pv@redpinesignals.com
Tue May 27 05:28:00 GMT 2014


Ian,

By packing the structure, issue got solved but generating more code.
How can I make our cross compiler to generate size of struct { short s;} 
as 2 instead of 4 ?

Is it required to change any macro's in port.h?

Please help me.

Thanks,
Siva prasad

On 05/23/2014 09:17 PM, Ian Lance Taylor wrote:
> On Fri, May 23, 2014 at 6:51 AM, Sivaprasad
> <sivaprasad.pv@redpinesignals.com> 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
>
>




More information about the Gcc-help mailing list