{$IFOPT A4}?

2020-07-20 08:07发布

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

The IFOPT directive seems to work only with pure switches ( {$IFOPT A4} does not compile ).

I couldn't find an equivalent constant or such defined ( {$IF Align = 4} or such )

4条回答
霸刀☆藐视天下
2楼-- · 2020-07-20 08:24

Write code to test the actual runtime behavior. Only way I can think of.

查看更多
贪生不怕死
3楼-- · 2020-07-20 08:25

There is {$IFOPT A+} directive, but it doesn't tell you alignment value.

查看更多
男人必须洒脱
4楼-- · 2020-07-20 08:32

You can do this by defining a record with known packing rules and check it using 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}
查看更多
▲ chillily
5楼-- · 2020-07-20 08:37

I believe there is no way to do this :(

查看更多
登录 后发表回答