-1

Delphi 可以对齐字、双字和四字边界上的记录,这取决于{$A}Delphi 的设置和版本。

如果我必须遵循(坏)代码:

  ofSize = $00;       <<-- hardcoded will break if I unpack the record.     
  ofMSB = $01;
  ofPtrDigits = $02;
  ofSign = $06;                 

  MinSizeBigint: Byte = 10;

type
  TBigint = packed record   
    Size: Byte;
    MSB: Byte;
    PtrDigits: Pointer;
    Sign: TSignValue;

我如何将其转换为:

type
  TBigint = record 
    PtrDigits: Pointer;  (*should be `array of cardinal`, but never mind that*)  
    Size: Byte;
    MSB: Byte;  
    Sign: TSignValue;

ofSize = OffsetOf(TBigInt.Size);    <<-- does a function like this exist?       
ofMSB = OffsetOf(TBigInt.Size);
ofPtrDigits = OffsetOf(TBigInt.Size);
ofSign = OffsetOf(TBigInt.Size);

是否有一个函数可以使用一些编译器魔法为我填充偏移量?

4

1 回答 1

-1

解决方法,但不是真正的答案...

替换此代码:

....
@Exit:
  mov   byte ptr [ebx+ofMsb], cl  <<-- hardcoded offset, only works with 
  mov   dword ptr [edi+edx*4], 1       `packed record`   
....

有了这个

@Exit:
  mov   byte ptr [ebx+TBigint.MSB], cl  <<-- Delphi will put the correct offset
  mov   dword ptr [edi+edx*4], 1
于 2013-09-15T00:25:01.050 回答