Hi
> I am generating my code with GNU-ARM..
> I have searched and found that the solution to this struct mis-alignment problem is:
> __attribute__((__packed__))
>
> Is there any compiler option, that would do the same for all structs I define?
> Or do I have to write this attribute to all of them?
> I found in gcc.pdf
>
> -fpack-struct
I strongly advise not to use a general option.
If you are free, re-order your structure-members, if not (given layout)
use __attribute__ .
Just in case you still want a global option, try -mstructure-size-boundary=8
But keep in mind, a packed structure like the following generates
horrible code:
struct a {
char c;
int i;
};
--
42Bastian
Note: SPAM-only account, direct mail to bs42@...
------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )
I must strongly agree with the two previous recommendations as well.
Also, something for you to think about.
I'm not sure what situation you're attempting to do this for, if it's a
matter of just framing some data from and inbound serial or Ethernet stream,
or something. But I would do it VERY sparingly, and only use it as long as
possible.
If you plan on manipulating this data much in any way (even just reading),
it's almost better to manually copy the data into an unpacked structure
because of the performance hit Bastian mentions, then copy it back.
Again, you know your situation better than we do, but keep that in mind.
Dave
-----Original Message-----
From: A...@yahoogroups.com [mailto:A...@yahoogroups.com] On Behalf Of
42Bastian
Sent: Tuesday, April 08, 2008 3:06 AM
To: A...@yahoogroups.com
Subject: Re: [AT91SAM] Struct alignment problem (GCC)
Hi
> I am generating my code with GNU-ARM..
> I have searched and found that the solution to this struct mis-alignment
problem is:
> __attribute__((__packed__))
>
> Is there any compiler option, that would do the same for all structs I
define?
> Or do I have to write this attribute to all of them?
> I found in gcc.pdf
>
> -fpack-struct
I strongly advise not to use a general option.
If you are free, re-order your structure-members, if not (given layout)
use __attribute__ .
Just in case you still want a global option, try -mstructure-size-boundary=8
But keep in mind, a packed structure like the following generates
horrible code:
struct a {
char c;
int i;
};
--
42Bastian
Note: SPAM-only account, direct mail to bs42@...
------------------------------------

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )