procedure Test(Value: Integer); overload;

procedure Test(Value: Integer); overload;
begin
ShowMessage('int')
end;

procedure Test(Value: Double); overload;
begin
ShowMessage('dbl')
end;

const
cValue: integer = 123;

begin
{1} Test(11 * Screen.PixelsPerInch / 96);
{2} Test(cValue + Round(11 * Screen.PixelsPerInch / 96));
{3} Test(cValue + Round(11 * 96 / 96));
{4} Test(Round(11 * Screen.PixelsPerInch / 96));
{5} Test(Round(11 * 96 / 96));
end.

What function you expect to be called at 1, 2, 3, 4, 5?

Comments

  1. David Heffernan you are right, this is expected behavior, but in fact {5} calls int version. Looks like round(const) is calculated by compiler, result interpreted as integer const and so Test(int) call is choosen.

    ReplyDelete
  2. Alexander Sviridenkov Does it matter what optimization is set to?

    ReplyDelete
  3. Alexander Sviridenkov that's a compiler bug then. The compiler optimisation needs to respect the fact that Round returns Int64. A bug report should be submitted.

    ReplyDelete

Post a Comment