Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-04

FPC can't determine overloaded function to call

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I can't figure out why FPC is struggling with figuring out which overloaded methods to call. This is my application code which FPC has a problem with.

type
  TPDFFloat = Single;
  TPDFCoord = record
    X,Y: TPDFFloat;
  end;
var
  W, H: integer
begin
  ...snip...
  P.DrawImage(25, 190, W div 2, H div 2, IDX);  // this fails
Yet this works
  P.DrawImage(25, 190, Integer(W div 2), Integer(H div 2), IDX);

Here are the overloaded DrawImage() definitions [sorry if you email client wraps this badly]:

{ X, Y coordinates are the bottom-left coordinate of the image. AWidth
and AHeight are in image pixels. }
Procedure DrawImage(const X, Y: TPDFFloat; const AWidth, AHeight,
ANumber: integer); overload;
Procedure DrawImage(const APos: TPDFCoord; const AWidth, AHeight,
ANumber: integer); overload;
{ X, Y coordinates are the bottom-left coordinate of the image. AWidth
and AHeight are in UnitOfMeasure units. }
Procedure DrawImage(const X, Y: TPDFFloat; const AWidth, AHeight:
TPDFFloat; ANumber: integer); overload;
Procedure DrawImage(const APos: TPDFCoord; const AWidth, AHeight:
TPDFFloat; ANumber: integer); overload;
This is the compiler error message I got:
==============================
Compile Project, Target: testfppdf: Exit code 1, Errors: 1, Hints: 2
testfppdf.lpr(281,46) Error: Can't determine which overloaded function
to call
fppdf.pp(1802,20) Hint: Found declaration: TPDFPage.DrawImage(const
Single,const Single,const Single,const Single,const LongInt);
fppdf.pp(1788,20) Hint: Found declaration: TPDFPage.DrawImage(const
Single,const Single,const LongInt,const LongInt,const LongInt);
==============================

Doesn't the code ⸢(W div 2)⸥ resolve to an Integer result? W is an Integer type, and DIV is an integer division.

I'm using 64-bit FPC 2.6.4.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp
Peter
to Graeme Geldenhuys
Graeme Geldenhuys wrote 63 lines
Hi, I can't figure out why FPC is struggling with figuring out which overloaded methods to call. This is my application code which FPC has a problem with. type TPDFFloat = Single; TPDFCoord = record X,Y: TPDFFloat; end; var W, H: integer begin ...snip... P.DrawImage(25, 190, W div 2, H div 2, IDX); // this fails Yet this works P.DrawImage(25, 190, Integer(W div 2), Integer(H div 2), IDX); Here are the overloaded DrawImage() definitions [sorry if you email client wraps this badly]: { X, Y coordinates are the bottom-left coordinate of the image. AWidth and AHeight are in image pixels. } Procedure DrawImage(const X, Y: TPDFFloat; const AWidth, AHeight, ANumber: integer); overload; Procedure DrawImage(const APos: TPDFCoord; const AWidth, AHeight, ANumber: integer); overload; { X, Y coordinates are the bottom-left coordinate of the image. AWidth and AHeight are in UnitOfMeasure units. } Procedure DrawImage(const X, Y: TPDFFloat; const AWidth, AHeight: TPDFFloat; ANumber: integer); overload; Procedure DrawImage(const APos: TPDFCoord; const AWidth, AHeight: TPDFFloat; ANumber: integer); overload; This is the compiler error message I got: ============================== Compile Project, Target: testfppdf: Exit code 1, Errors: 1, Hints: 2 testfppdf.lpr(281,46) Error: Can't determine which overloaded function to call fppdf.pp(1802,20) Hint: Found declaration: TPDFPage.DrawImage(const Single,const Single,const Single,const Single,const LongInt); fppdf.pp(1788,20) Hint: Found declaration: TPDFPage.DrawImage(const Single,const Single,const LongInt,const LongInt,const LongInt); ============================== Doesn't the code ⸢(W div 2)⸥ resolve to an Integer result? W is an Integer type, and DIV is an integer division. I'm using 64-bit FPC 2.6.4. Regards, Graeme

Sizeof 'W' is 2
Sizeof '(W div 2)' is 8

I suspect '(W div 2) gives int64.

Regards,
Pete

Graeme Geldenhuys
to Peter
Peter wrote
I suspect '(W div 2) gives int64.

Interesting thought. But a Integer div Integer cannot give a result larger than a Integer type, so why is the compiler upscaling the result it to a Int64?? If that is really what the compiler is doing, then something is going way wrong, or I simply don't understand the logic.

I looked through the help, and the Objects.pp unit actually has a LongDiv() method which does a DIV between two Integer types and returns a Integer [as one would expect the result to be]. But looking at its implementation I see it required a Integer cast too. Very strang compiler behaviour. :-/

FUNCTION LongDiv (X: LongInt; Y: Integer): Integer;
BEGIN
  LongDiv := Integer(X DIV Y);
END;

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp
Graeme Geldenhuys
to Graeme Geldenhuys: I can't figure out why FPC is struggling with figuring out which overloaded methods to…
Graeme Geldenhuys wrote 5 lines
...snip... P.DrawImage(25, 190, W div 2, H div 2, IDX); // this fails Yet this works P.DrawImage(25, 190, Integer(W div 2), Integer(H div 2), IDX);

In this specific example, the following also works - and without the need for the Integer() casting.

  P.DrawImage(25, 190, W shr 1, H shr 1, IDX);

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp
Jonas Maebe
to Graeme Geldenhuys: Interesting thought. But a Integer div Integer cannot give a result larger than a Integer…
Graeme Geldenhuys wrote
Interesting thought. But a Integer div Integer cannot give a result larger than a Integer type, so why is the compiler upscaling the result it to a Int64?? If that is really what the compiler is doing, then something is going way wrong, or I simply don't understand the logic.

Search for "As a pascal compiler" on
http://www.freepascal.org/docs-html/ref/refsu5.html

You are presumably compiling for a 64 bit target platform.

Jonas