Re: Bytes alignement problem with arm-linux-gcc

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

 



> Normally we will have the following sizes:
>     sizeof(a.msg) = 14
>     sizeof(a.NAMEDFIELD.error) = 1
>     sizeof(a.NAMEDFIELD.entete) = 4
>     sizeof(a.lNAMEDFIELD.en) = 1
>     sizeof(a.NAMEDFIELD.data) = 8.
> So we can think that sizeof(a.msg)=sizeof(a.NAMEDFIELD)

No, structure layout doesn't work like that.

> but sizeof(a.NAMEDFIELD)=20 ...

Yes, it follows the ABI rules: 'long' are aligned on n-byte boundaries, the 
size of the structure must be a multiple of the alignment and so on.

> How can this problem can be resolved?

Put __attribute__((packed)) on the structure.

-- 
Eric Botcazou

[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