Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting Delphi code to 64 bit - Why no compiler warnings?

We have a large Delphi XE codebase we want to port to 64 bit.

I own a Delphi XE2 licence and I cannot find any warning nor hint that can help me to detect valid 32 bit constructions that can now lead to data loss under a 64 bit platform. For instance, THandle to Cardinal assignments which were perfectly valid with the 32 bit compiler don’t raise any warning when compiling for Win64.

When migrating to Unicode with Delphi 2009, we had tons of warnings that helped us a lot to track and fix suspicious code. With XE2, I can’t find anything. I can’t imagine there is nothing integrated on the compiler level to avoid us to do a manual review of all our code.

Do I miss something ? How did you port you projects to 64 bit, if you tried ?

Thanks !

like image 601
Adrien Reboisson Avatar asked Nov 04 '11 19:11

Adrien Reboisson


1 Answers

You did not miss anything. There is nothing in the product to help you.

I too find this a little disappointing but I fully expect that the Emba designers thought about this. I can only conclude that their experience was that adding such warnings resulted in more noise than signal. The Delphi compiler has never warned when assigning to incompatible integer types. For example it has never been a warning or an error to assign an integer to a byte.

It's time to fire up grep and search for Integer\(.*\), Longint\(.*\), Cardinal\(.*\), Longword\(.*\), THandle etc.


To respond to Arnaud's comment and answer, I offer the following code which compiles free of warnings and errors when targetting 64 bit.

procedure NaughtyCode;
var
  Handle: THandle;
  int: Integer;
  card: Cardinal;
  P: Pointer;
begin
  Handle := high(Handle);
  int := Handle;
  card := Handle;
  P := Pointer(Handle);
  int := Integer(P);
  card := Cardinal(P);
end;
like image 185
David Heffernan Avatar answered Nov 15 '22 21:11

David Heffernan