01-30-07 12:23 AM
"Andrew Falanga" <af300wsm@gmail.com> wrote in message
news:1170105531.486275.154120@h3g2000cwc.googlegroups.com...
> Is there a way using GNU GCC, to double word align an array?
> Something like a macro or similar (or whatever it might be if it
> exists)? I'd like to have my integer array start on a double word
> address boundary for testing a theory on a program I'm writing.
>
> My understanding of byte alignmens is quite limited and if I'm not
> asking the question correctly, please forgive me. What I'm trying to
> avoid is over burden code to build an array and then double word align
> the array after it's been defined.
Usually, you don't have worry about this at all.
If you simply define an array, i.e.
int x[20];
or
long x [20];
or
p = malloc(20 * sizeof(long));
the compiler handles the alignment issues so as to avoid illegal addressing
or performance issues. In the first two cases, the C compiler will generate
the right code. In the last case, the result of malloc() is guaranteed to
have the most stringent alignment ever necessary.
If you want to have an "int" aligned on a boundary necessary for a "long",
then you've generally got other problems using the C language (i.e. there is
something else about your problem I'm not understanding).
There is generally no performance advantage to aligning data more
stringently than required for the data type. If such advantages exist, the
compiler generally knows about them.
--
David T. Ashley (dta@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
[ Post a follow-up to this message ]
|