Recent

Author Topic: Question about {$ALIGN xxx}  (Read 3140 times)

440bx

  • Hero Member
  • *****
  • Posts: 2469
Question about {$ALIGN xxx}
« 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.              
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 900
Re: Question about {$ALIGN xxx}
« Reply #1 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

440bx

  • Hero Member
  • *****
  • Posts: 2469
Re: Question about {$ALIGN xxx}
« Reply #2 on: June 25, 2021, 09:09:01 am »
Thank you Jonas.  I appreciate your answering and the explanation.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

 

TinyPortal © 2005-2018