This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: DATA_ALIGNMENT vs. DECL_USER_ALIGNMENT
- From: dewar at gnat dot com (Robert Dewar)
- To: aoliva at redhat dot com, dewar at gnat dot com
- Cc: gcc-patches at gcc dot gnu dot org, gcc at gcc dot gnu dot org,kenner at vlsi1 dot ultra dot nyu dot edu, rth at redhat dot com
- Date: Mon, 21 Apr 2003 17:35:51 -0400 (EDT)
- Subject: Re: DATA_ALIGNMENT vs. DECL_USER_ALIGNMENT
> So if you turn:
>
> T i __attribute__((align(2)));
> T j __attribute__((align(2)));
>
> into
>
> typedef T T2 __attribute__((align(2)));
> T2 i, j;
>
> you say we could get different code? It sounds to me like they
> *should* be equivalent. The compiler can't tell whether the user
> meant the alignment of a type is meant for composites only or for
> factoring of attributes in object declarations.
Yes, at least that's the intention in Ada. Setting an alignment for a type
specifies a minimum alignment for objects.
Consider the following
type A is ....
for A'Alignment use 4;
B : A:
Put_Line (Integer'Image (B'Alignment));
Ada semantics say that the value printed must be 4 or a multiple of 4.
type A is ...
B : A;
for B'Alignment use 4;
Put_Line (Integer'Image (B'Alignment));
This must output 4. Of course the compiler could still silently put
B on a bigger alignment, since there would be no way to tell that it
was doing this systematically, but this would be a poor implementation.