This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


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: Structure alignment problem


Hello,

On Thu, Sep 12, 2002 at 11:48:45AM +0200, Rosetti Andrea wrote:
> My problem is to set the max alignment size for the structure members
> because I use different compilers for different targets
> and I have compatibility problems.
> 
> For example:
> 
> struct {
>  int a;
>  char b;
>  int c;
> } pippo;
> 
> void bye ()
> {
>   pippo.a=4;
>   pippo.b='4';
>   pippo.c=9;
> 
> }

You can't expect C to produce consistent code for something
like that. Alignement isn't defined. All you know is that
the same compiler will use a consistent policy (ie if you
use that same struct in 2 different places, you'll get the
same alignement).

If you need to exchange structs between targets (or even
between applications produced with different compilers, I'd
guess), you'll need to define your structs as packed in a
way I can't quite recall but it'd look something like:

struct {
  int a;
  char b;
  int c;
} pippo __attribute("PACK");

See GCC Manual for details...

HTH
/Y


------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]