Sign in

username:

password:



Not a member?

Search AT91SAM



Search tips

Subscribe to AT91SAM



Ads

Discussion Groups

Discussion Groups | AT91SAM ARM | Re: Struct alignment problem (GCC)

For users of the Atmel AT91SAM7 and AT91SAM9 ARM CPU chips. Atmel has taken a new direction by combining on chip flash and ram with the ARM CPU on a single die. This provides low cost devices for small systems using the ARM CPU. This group is to exchange information to help users get started and learn how to use the devices.

Re: Struct alignment problem (GCC) - 42Bastian - Apr 8 4:19:34 2008

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 )


RE: Struct alignment problem (GCC) - David Gacke - Apr 8 18:50:18 2008

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 )