FPC can't determine overloaded function to call

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

FPC can't determine overloaded function to call

Graeme Geldenhuys-6
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC can't determine overloaded function to call

Peter
On 28/04/16 14:02, Graeme Geldenhuys wrote:

> 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



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC can't determine overloaded function to call

Graeme Geldenhuys-6
On 2016-04-28 14:22, 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC can't determine overloaded function to call

Graeme Geldenhuys-6
In reply to this post by Graeme Geldenhuys-6
On 2016-04-28 14:02, Graeme Geldenhuys wrote:
>   ...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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC can't determine overloaded function to call

Jonas Maebe-2
In reply to this post by Graeme Geldenhuys-6
On 28/04/16 15:33, 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal