Reported by Primoz Gabrijelcic
(reposted from borland.public.delphi.objectpascal)
Miha Remec and I stumbled across some int64 incompatibility when trying to
compile old code to Delphi 5. This is a minimized version of the problem.
Try to compile that:
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
program int64bug;
{$APPTYPE CONSOLE}
uses sysutils;
type
Tbug = class
field: int64;
constructor Create;
end;
{ Tbug }
constructor Tbug.Create;
begin
inherited;
Int64Rec(field).Lo := 0; // !!!
end;
begin
end.
Delphi reports 'Left side cannot be assigned to' on the marked line. This
code works perfectly well in D4. As far as I'm concerned it is perfectly
valid, too. Can somebody enlighten me with an explanation?
Even more interesting: if I have a simple global (or local) variable of type
int64, compiler does its job good. This compiles correctly, for example:
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
program int64bug;
{$APPTYPE CONSOLE}
uses sysutils;
var
global: int64;
begin
Int64Rec(global).Lo := 0;
end.
*BUT* if you complicate the casting enough, compiler eventually dies. This,
for example does not work (same error - left side...):
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
program int64bug;
{$APPTYPE CONSOLE}
uses sysutils;
var
global: int64;
begin
Int64Rec(int64((@global)^)).Lo := 0;
end.
(additional comment by Robert Lee)
ell figured out what I had been seeing before. It's not exactly the same,
but I has the same workaround. Also, I poked around in the problem and it
does seem quite strange that for instance you can cast a double, which is
also 8 bytes, into any like sized structure, but not int64. I think you'll
find this amusing as well
TSomeClass=class
Data:int64;
...
end;
...
int64(Data):=3;
'Left side cannot be signed to' !!! You can't even cast it to itself. OK,
it's a bug. |