Discussion:
[fpc-pascal] Can't determine which overloaded function to call
LacaK
2018-12-04 12:21:50 UTC
Permalink
Hi *,

this code compiles for target Win32 but does not compile for
Win64/x86-64. Why? Is there workaround?
(Error: Can't determine which overloaded function to call)
Thank you
-Laco.

=== code sample ===

  TRec1 = record
    x,y: integer;
    function Offset(const Ax,Ay: integer): TRec1; overload;
    function Offset(const Ax,Ay: single): TRec1; overload;
  end;

function TRec1.Offset(const Ax,Ay: integer): TRec1;
begin
end;

function TRec1.Offset(const Ax,Ay: single): TRec1;
begin
end;

var
  r1: TRec1;
  a,b: integer;

begin
  r1 := r1.Offset(a-1,b-1); // HERE Error:
end.  

============================

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pasca
Santiago A.
2018-12-04 15:13:19 UTC
Permalink
Post by LacaK
Hi *,
this code compiles for target Win32 but does not compile for
Win64/x86-64. Why? Is there workaround?
(Error: Can't determine which overloaded function to call)
Thank you
For me, in win32 works fine

try this

r1.Offset(a-Integer(1),b-Integer(1));

or

r1.Offset(Integer(a-1),Integer(b-1));
--
Saludos

Santiago A.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi
LacaK
2018-12-05 06:51:10 UTC
Permalink
Post by Santiago A.
Post by LacaK
Hi *,
this code compiles for target Win32 but does not compile for
Win64/x86-64. Why? Is there workaround?
(Error: Can't determine which overloaded function to call)
Thank you
For me, in win32 works fine
Yes in Win32 works also for me. And this is my question why it does work
in Win32 and does not work in Win64?
Post by Santiago A.
try this
r1.Offset(a-Integer(1),b-Integer(1));
does not helps
Post by Santiago A.
or
r1.Offset(Integer(a-1),Integer(b-1));
helps, but why is it not needed in Win32? Why for Win32
"integer"-"integer" is considered as "integer" so compiler can determine
which overloaded function to call and for Win64 compiler compiler can
NOT determine which overloaded function to call?

It seems to me as inconsistent?

L.

=== code sample ===

  TRec1 = record
    x,y: integer;
    function Offset(const Ax,Ay: integer): TRec1; overload;
    function Offset(const Ax,Ay: single): TRec1; overload;
  end;

function TRec1.Offset(const Ax,Ay: integer): TRec1;
begin
end;

function TRec1.Offset(const Ax,Ay: single): TRec1;
begin
end;

var
  r1: TRec1;
  a,b: integer;

begin
  r1 := r1.Offset(a-1,b-1); // HERE Error:
end.  

============================


_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lis
Jonas Maebe
2018-12-05 07:46:33 UTC
Permalink
Post by LacaK
helps, but why is it not needed in Win32? Why for Win32
"integer"-"integer" is considered as "integer" so compiler can determine
which overloaded function to call and for Win64 compiler compiler can
NOT determine which overloaded function to call?
It is because as documented at
https://www.freepascal.org/docs-html/ref/refsu4.html (remarks under
table 3.2), FPC evaluates integer expressions using the native integer
type of the platform. On Win32 this is 32 bit, while on Win64 this is 64
bit. On the other hand, "integer" is always 32 bit in Delphi mode.

This means that on Win32, there is an exact match for overload selection
in your test program, while on Win64 there is not and the int64 ->
integer and int64 -> single type conversions have the same priority.


Jonas
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailma
LacaK
2018-12-05 10:55:52 UTC
Permalink
Post by Jonas Maebe
Post by LacaK
helps, but why is it not needed in Win32? Why for Win32
"integer"-"integer" is considered as "integer" so compiler can determine
which overloaded function to call and for Win64 compiler compiler can
NOT determine which overloaded function to call?
It is because as documented at
https://www.freepascal.org/docs-html/ref/refsu4.html (remarks under
table 3.2), FPC evaluates integer expressions using the native integer
type of the platform.
Do you mean: "2. Every integer smaller than the ”native” size is
promoted to a signed version of the ”native” size. Integers equal to the
”native” size keep their signedness. "?
Post by Jonas Maebe
On Win32 this is 32 bit, while on Win64 this is 64 bit. On the other
hand, "integer" is always 32 bit in Delphi mode.
This means that on Win32, there is an exact match for overload
selection in your test program, while on Win64 there is not and the
int64 -> integer and int64 -> single type conversions have the same
priority.
I understand now. Although I must say that it is bit unintuitive for me ;-)

So I can workaround using:
    function Offset(const Ax,Ay: PtrInt): TRec1; overload;

Thank you for explanation

-Laco.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://
Santiago A.
2018-12-05 16:26:25 UTC
Permalink
Post by Jonas Maebe
Post by LacaK
helps, but why is it not needed in Win32? Why for Win32
"integer"-"integer" is considered as "integer" so compiler can determine
which overloaded function to call and for Win64 compiler compiler can
NOT determine which overloaded function to call?
It is because as documented at
https://www.freepascal.org/docs-html/ref/refsu4.html (remarks under
table 3.2), FPC evaluates integer expressions using the native integer
type of the platform. On Win32 this is 32 bit, while on Win64 this is
64 bit. On the other hand, "integer" is always 32 bit in Delphi mode.
This means that on Win32, there is an exact match for overload
selection in your test program, while on Win64 there is not and the
int64 -> integer and int64 -> single type conversions have the same
priority.
do  (LongInt -> Integer) and (Longint -> single) have the same priority?
--
Saludos

Santiago A.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/
Loading...