[uClinux-dev] structure size ????

Christian Pellegrin chri at infis.univ.trieste.it
Mon Mar 3 08:53:01 EST 2003


On Mon, 3 Mar 2003, Thomas Chen wrote:

> 
> a lot of interesting discussion on this... but my original question
> was: is there any way to tell compiler (for arm7tdmi) to align
> on 16 bit boundry instead of 32 ???
> 

Look for the __attribute__ to gcc (in the info manual under compiler 
extension, variabile attribute). There is an attribute called alligned 
that should do the trick. I cut&paste some words from there ....

HTH,
Bye!

`aligned (ALIGNMENT)'
     This attribute specifies a minimum alignment for the variable or
     structure field, measured in bytes.  For example, the declaration:

          int x __attribute__ ((aligned (16))) = 0;

     causes the compiler to allocate the global variable `x' on a
     16-byte boundary.  On a 68040, this could be used in conjunction
     with an `asm' expression to access the `move16' instruction which
     requires 16-byte aligned operands.

     You can also specify the alignment of structure fields.  For
     example, to create a double-word aligned `int' pair, you could
     write:

          struct foo { int x[2] __attribute__ ((aligned (8))); };

     This is an alternative to creating a union with a `double' member
     that forces the union to be double-word aligned.

     As in the preceding examples, you can explicitly specify the
     alignment (in bytes) that you wish the compiler to use for a given
     variable or structure field.  Alternatively, you can leave out the
     alignment factor and just ask the compiler to align a variable or
     field to the maximum useful alignment for the target machine you
     are compiling for.  For example, you could write:

          short array[3] __attribute__ ((aligned));




More information about the uClinux-dev mailing list