This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Bytes alignement problem with arm-linux-gcc
- From: Eric Botcazou <ebotcazou at libertysurf dot fr>
- To: "Frederic Kwiatkowski" <stagedrt at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 8 Feb 2007 15:39:25 +0100
- Subject: Re: Bytes alignement problem with arm-linux-gcc
- References: <5fb065d90702080255vf9b39c6n78a2221761ad967@mail.gmail.com>
> 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