Hi again,
I reply also to fpc-devel list (excuse me, if it is off-topic), because I would like understand wat is going on.
I attach also simple test program.
I use FPC 2.6.4 but I think, that same happens also with fresh 2.7.1
Thanks
-Laco.

On 02.05.2014 07:45, LacaK wrote:
Hi,
I am trying understand how FPC determines which version of overloaded
function to call.
Take as example these 2 functions (from SysUtils):
1. function StrPLCopy(Dest: PChar; Source: string; MaxLen: SizeUInt):
PChar; overload;
2. function StrPLCopy(Dest: PWideChar; const Source: UnicodeString;
MaxLen: SizeInt): PWideChar; overload;

And in program I use:
var p: pointer;
      s: string;
begin
   StrPLCopy(p, s, 10);
end;

It seems, that 2nd "unicode" version of StrPLCopy is called. But why?
I am thinking as:
1st parameter is untyped pointer, so no one of function can be prefered
2nd parameter is "string" which exactly match 1st function signature
3rd parameter is "integer constant" which mach both signatures

So it seems to me, that 1st version of function signature matches
better, because of exact match of 2nd parameter ... why is then called
2nd version?

I don't have a explanation for now, but it *might* be important to note whether you are using 2.6.x or 2.7.1.

Regards,
Sven

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


program test_StrPLCopy;

{$mode objfpc}{$H+}

uses
   {$IFDEF UNIX}{$IFDEF UseCThreads}
   cthreads,
   {$ENDIF}{$ENDIF}
   Classes
   { you can add units after this };

function StrPLCopy(Dest: PChar; Source: string; MaxLen: SizeUInt): 
PChar;overload;
begin
  writeln('Ansi version');
end;

function StrPLCopy(Dest: PWideChar; const Source: UnicodeString; MaxLen: 
SizeInt): PWideChar; overload;
begin
  writeln('Unicode version');
end;

var
  p: pointer;
  s: string;

begin
  StrPLCopy(p, s, 10);
  readln;
end.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to