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]

Re: Bytes alignement problem with arm-linux-gcc


> 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]