class Extended 类型的运算符在 BDS2006 中不起作用?
class operator with result of Extended type does not work in BDS2006?
如果我尝试编译以下代码,我收到最后一行的错误消息 "E2010 Incompatible types: 'Extended' and 'TMyRec'" (E := R):
type
TMyRec = record
class operator Implicit(Rec: TMyRec) : Integer;
class operator Implicit(Rec: TMyRec) : Extended;
end;
class operator TMyRec.Implicit(Rec: TMyRec) : Integer;
begin
Result := 1;
end;
class operator TMyRec.Implicit(Rec: TMyRec) : Extended;
begin
Result := 1;
end;
var
R : TMyRec;
B : Byte;
E : Extended;
begin
B := R; //this is OK
E := R; //E2010 Incompatible types: 'Extended' and 'TMyRec'
end.
请朋友尝试用XE编译,编译成功。那么这是 BDS2006 中的错误吗?有什么办法可以解决这个问题吗?
这确实是一个编译器缺陷。修复它的唯一方法是升级到可以解决该缺陷的编译器版本。如果您做不到,您只需要以不同的方式编写代码。
FWIW,在我看来,使用 Extended
总是错误的。这种类型是非标准的,只存在于 x86 上。在将来的某个时候,如果您移动到 x64,您会发现 Extended
被映射到 Double
。此外,类型的对齐会导致内存访问性能不佳,并且将数据存储为 Extended
而不是 Double
的程序往往会明显变慢。
如果我尝试编译以下代码,我收到最后一行的错误消息 "E2010 Incompatible types: 'Extended' and 'TMyRec'" (E := R):
type
TMyRec = record
class operator Implicit(Rec: TMyRec) : Integer;
class operator Implicit(Rec: TMyRec) : Extended;
end;
class operator TMyRec.Implicit(Rec: TMyRec) : Integer;
begin
Result := 1;
end;
class operator TMyRec.Implicit(Rec: TMyRec) : Extended;
begin
Result := 1;
end;
var
R : TMyRec;
B : Byte;
E : Extended;
begin
B := R; //this is OK
E := R; //E2010 Incompatible types: 'Extended' and 'TMyRec'
end.
请朋友尝试用XE编译,编译成功。那么这是 BDS2006 中的错误吗?有什么办法可以解决这个问题吗?
这确实是一个编译器缺陷。修复它的唯一方法是升级到可以解决该缺陷的编译器版本。如果您做不到,您只需要以不同的方式编写代码。
FWIW,在我看来,使用 Extended
总是错误的。这种类型是非标准的,只存在于 x86 上。在将来的某个时候,如果您移动到 x64,您会发现 Extended
被映射到 Double
。此外,类型的对齐会导致内存访问性能不佳,并且将数据存储为 Extended
而不是 Double
的程序往往会明显变慢。