{$ IFOPT A4}?

In Delphi 2009 (or older versions), how do you check the "Align" compilation option in your code?

The directive IFOPTonly works with clean switches ( {$IFOPT A4}not compiled).

I could not find an equivalent constant or such specific ( {$IF Align = 4}or such)

+3
source share
4 answers

You can do this by specifying a record with known packaging rules and checking it with SizeOf. Tested in Delphi 2009:

type
  TTestRec = record
    A: Byte;
    B: Int64;
  end;

{$IF SIZEOF(TTestRec) = 9}
  {$MESSAGE HINT '$A1'}
{$ELSEIF SIZEOF(TTestRec) = 10}
  {$MESSAGE HINT '$A2'}
{$ELSEIF SIZEOF(TTestRec) = 12}
  {$MESSAGE HINT '$A4'}
{$ELSEIF SIZEOF(TTestRec) = 16}
  {$MESSAGE HINT '$A8'}
{$ELSE}
  {$MESSAGE HINT 'Unknown alignment'}
{$IFEND}
+10
source

Enter the code to verify the actual runtime behavior. The only way I can think of.

+3
source

{$ IFOPT A +}, .

+1

, : (

0

Source: https://habr.com/ru/post/1707758/


All Articles