加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 什么是“Packed Now Forces Byte对齐记录”是什么意思

发布时间:2020-12-15 10:17:39 所属栏目:大数据 来源:网络整理
导读:Delphi XE2的新功能包含 following。 Packed Now Forces Byte Alignment of Records If you have legacy code that uses the packed record type and you want to link with an external DLL or with C++,you need to remove the word “packed” from your
Delphi XE2的新功能包含 following。

Packed Now Forces Byte Alignment of Records

If you have legacy code that uses the packed record type and you want
to link with an external DLL or with C++,you need to remove the word
“packed” from your code. The packed keyword now forces byte alignment,
whereas in the past it did not necessarily do this. The behavior
change is related to C++ alignment compatibility changes in Delphi
2009.

我不明白这个我正在努力解决这一点:而在过去,它并不一定这样做。我不能调和的是,我最了解的是,包装一直导致记录的字节对齐。任何人都可以给出一个不是字节对齐的打包记录的例子?显然这必须在一个较早的版本。

为什么文档说“如果你想链接一个外部DLL或C,你需要删除从你的代码打包的单词”?如果外部代码使用#pragma pack(1),那么如果打包超限,我们该怎么办?

$ ALIGN指令呢? {$ A1}和{$ A-}等同于包装,还是包装有一些额外的意义?

似乎我错过了一些东西,如果有人能解释这个话,会很感激。还是文档真的很差?

更新

我相信文档是指记录本身的对齐,而不是记录的布局。这是一个小程序,显示使用打包在记录上强制将记录对齐为1。

program PackedRecords;
{$APPTYPE CONSOLE}
type
  TPackedRecord = packed record
    I: Int64;
  end;

  TPackedContainer = record
    B: Byte;
    R: TPackedRecord;
  end;

  TRecord = record
    I: Int64;
  end;

  TContainer = record
    B: Byte;
    R: TRecord;
  end;

var
  pc: TPackedContainer;
  c: TContainer;

begin
  Writeln(NativeInt(@pc.R)-NativeInt(@pc.B));//outputs 1
  Writeln(NativeInt(@c.R)-NativeInt(@c.B));//outputs 8
  Readln;
end.

这在Delphi 6,2010,XE和XE2 32位和XE 64位上产生相同的输出。

解决方法

文档的最新更新已经删除了该问题所基于的所有文本。我的结论是,原文只是一个文档错误。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读