将C结构转换为delphi
我需要将下面的结构转换为delphi。我对“:4”值在“保留”和“版本”成员中的含义表示怀疑。看起来它干扰了结构的大小!有人给你小费吗将C结构转换为delphi,delphi,delphi-xe,Delphi,Delphi Xe,我需要将下面的结构转换为delphi。我对“:4”值在“保留”和“版本”成员中的含义表示怀疑。看起来它干扰了结构的大小!有人给你小费吗 typedef struct _FSRTL_COMMON_FCB_HEADER { CSHORT NodeTypeCode; CSHORT NodeByteSize; UCHAR Flags; UCHAR IsFastIoPossible; UCHAR Flags2;
typedef struct _FSRTL_COMMON_FCB_HEADER {
CSHORT NodeTypeCode;
CSHORT NodeByteSize;
UCHAR Flags;
UCHAR IsFastIoPossible;
UCHAR Flags2;
UCHAR Reserved :4;
UCHAR Version :4;
PERESOURCE Resource;
...
这些是位字段。Delphi不直接支持它们,但有一些解决方法,请参见,尤其是。正如前面的评论所述,这是一个位字段,即一组位,共同构成一个字节、字或dword 最简单的解决方案是:
type
_FSRTL_COMMON_FCB_HEADER = record
private
function GetVersion: Byte;
procedure SetVersion(Value: Byte);
public
NodeTypeCode: Word;
...
ReservedVersion: Byte; // low 4 bits: reserved
// top 4 bits: version
// all other fields here
property Version: Byte read GetVersion write SetVersion;
// Reserved doesn't need an extra property. It is not used.
end;
...
implementation
function _FSRTL_COMMON_FCB_HEADER.GetVersion: Byte;
begin
Result := (ReservedVersion and $F0) shr 4;
end;
procedure _FSRTL_COMMON_FCB_HEADER.SetVersion(Value: Byte);
begin
ReservedVersion := (Value and $0F) shl 4;
end;
在我的文章中可以找到一个不太简单(但更一般)的解决方案和解释:,Uli已经链接到了它。位数。记录如下,因为还标记了Pascal:Free Pascal确实支持位字段。啊,谢谢,我只是想发布相同的链接(第二个链接)。