This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]