gpt4 book ai didi

delphi - 哪些与指针相关的东西在 Delphi XE8 的移动编译器中不起作用?

转载 作者:行者123 更新时间:2023-12-03 15:11:06 25 4
gpt4 key购买 nike

Embarcadero 的 docwiki 页面 LLVM-based Delphi Compilers列出了 Delphi XE8 中的几项语言更改。其中一颗子弹说:

Use of pointers is not supported by LLVM-based Delphi compilers.

这在实践中到底意味着什么?哪些与指针相关的东西曾经在 Delphi XE7 中工作,但在 Delphi XE8 中不再工作?我似乎无法在 Embarcadero 的网站上找到对此的深入解释。页面Migrating Delphi Code to Mobile from Desktop据说包含更多信息,例如没有提到“指针”一词。

最佳答案

Use of pointers is not supported by LLVM-based Delphi compilers.

这一定是文档中的错误。看看 RTL 就知道了。它对指针的使用很厚。

例如,CompareMem 怎么样。它的定义如下:

function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;

实现的运行方式如下:

function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;
{$IF defined(POSIX)}
begin
if Length <= 0 then
Result := True
else
Result := memcmp(P1^, P2^, Length) = 0;
end;
{$ELSEIF defined(PUREPASCAL)}
....
{$ENDIF !PUREPASCAL}

POSIX 代码由移动目标使用。

或者 TObject 看起来像这样:

type
TObject = class
public
constructor Create;
procedure Free;
procedure DisposeOf; {$IFNDEF AUTOREFCOUNT} inline; {$ENDIF}
class function InitInstance(Instance: Pointer): TObject {$IFDEF AUTOREFCOUNT} unsafe {$ENDIF};
procedure CleanupInstance;
function ClassType: TClass; inline;
class function ClassName: string;
class function ClassNameIs(const Name: string): Boolean;
class function ClassParent: TClass;
class function ClassInfo: Pointer; inline;
class function InstanceSize: Integer; inline;
class function InheritsFrom(AClass: TClass): Boolean;
class function MethodAddress(const Name: _ShortStr): Pointer; overload;
class function MethodAddress(const Name: string): Pointer; overload;
class function MethodName(Address: Pointer): string;
class function QualifiedClassName: string;
function FieldAddress(const Name: _ShortStr): Pointer; overload;
function FieldAddress(const Name: string): Pointer; overload;
function GetInterface(const IID: TGUID; out Obj): Boolean;
class function GetInterfaceEntry(const IID: TGUID): PInterfaceEntry;
class function GetInterfaceTable: PInterfaceTable;
class function UnitName: string;
class function UnitScope: string;
{$IFDEF AUTOREFCOUNT}
function __ObjAddRef: Integer; virtual;
function __ObjRelease: Integer; virtual;
{$ENDIF}
function Equals(Obj: TObject): Boolean; virtual;
function GetHashCode: Integer; virtual;
function ToString: string; virtual;
function SafeCallException(ExceptObject: TObject;
ExceptAddr: Pointer): HResult; virtual;
procedure AfterConstruction; virtual;
procedure BeforeDestruction; virtual;
procedure Dispatch(var Message); virtual;
procedure DefaultHandler(var Message); virtual;
class function NewInstance: TObject {$IFDEF AUTOREFCOUNT} unsafe {$ENDIF}; virtual;
procedure FreeInstance; virtual;
{$IFDEF AUTOREFCOUNT}
protected
{$ENDIF}
destructor Destroy; virtual;

{$IFDEF CPP_ABI_SUPPORT}
procedure CPP_ABI_1; virtual;
procedure CPP_ABI_2; virtual;
procedure CPP_ABI_3; virtual;
{$ENDIF !CPP_ABI_SUPPORT}

protected
function GetDisposed: Boolean; inline;
procedure CheckDisposed; {$IFNDEF AUTOREFCOUNT} inline; {$ENDIF}

{$IFDEF AUTOREFCOUNT}
private const
objDestroyingFlag = Integer($80000000);
objDisposedFlag = Integer($40000000);
protected
[Volatile] FRefCount: Integer;
class procedure __MarkDestroying(const Obj); static; inline;
class function __SetDisposed(const Obj): Boolean; static; inline;
public
property RefCount: Integer read FRefCount;
{$ENDIF}
property Disposed: Boolean read GetDisposed;
end;

很明显,这里在移动平台上使用了指针。

阅读有关该主题的 Embarcadero 白皮书:The Delphi Language for Mobile Development 。它再次涵盖了指针在多种场合的使用,并且很明显它们是受支持的。现在,确实不鼓励使用指针,如果可以轻松避免使用指针,那么鼓励您这样做。但这与声明编译器不支持指针有很大不同。

Embarcadero 正在传播对自己产品的 FUD,这至少有点讽刺意味。

关于delphi - 哪些与指针相关的东西在 Delphi XE8 的移动编译器中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31115037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com