Lazarus

Free Pascal => General => Topic started by: 440bx on June 25, 2021, 01:15:43 am

Title: Question about {$ALIGN xxx}
Post by: 440bx on June 25, 2021, 01:15:43 am
Hello,

Based on the description of {$ALIGN xx} in the programmer's guide, I expected the fields of the record in the sample program below to be aligned on a 32 byte boundary but, they aren't, since if they were the record size could not be 16 bytes.   What am I missing ?

test program follows:
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2.  
  3. {$ALIGN 32}   { doesn't seem to change the record size }
  4.  
  5. program TestAlignment;
  6.  
  7. type
  8.   ARecord = record
  9.     A         : qword;
  10.     B         : qword;
  11.   end;
  12.  
  13. begin
  14.   writeln;
  15.   writeln;
  16.  
  17.   writeln('  sizeof ARecord = ', sizeof(ARecord));
  18.  
  19.   writeln;
  20.   writeln;
  21.   writeln('press ENTER/RETURN to end this program');
  22.   readln;
  23. end.              
Title: Re: Question about {$ALIGN xxx}
Post by: Jonas Maebe on June 25, 2021, 08:17:51 am
{$align 32} changes the maximum possible alignment. It does not change the minimum required alignment. Since the native alignment for qword is 8 bytes, it indeed won't have any effect. It would only have an effect for hypothetical vector types with a 32 byte alignment requirement.

To change the minimal required alignment, use this directive: https://www.freepascal.org/docs-html/prog/progsu9.html
Title: Re: Question about {$ALIGN xxx}
Post by: 440bx on June 25, 2021, 09:09:01 am
Thank you Jonas.  I appreciate your answering and the explanation.
TinyPortal © 2005-2018