Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

function Copy() in Free Pascal

Delphi allows 3 versions of the Copy function:

function CopyTest(const S: string): string;
begin
  Result:= Copy(S, 1, 5);
  Result:= Copy(S, 1);
//  Result:= Copy(S);   //  not allowed for strings, allowed for dyn arrays
end;

FreePascal seems to compile only the 1st (3-arg) version; for the others I have compile-time error

Error: Wrong number of parameters specified for call to "$fpc_ansistr_copy"

Am I missing some FPC compiler switch or Copy overloads are not available in Free Pascal?

like image 372
kludg Avatar asked Sep 22 '12 08:09

kludg


People also ask

What is Val Pascal?

Description. Val converts the value represented in the string S to a numerical value or an enumerated value, and stores this value in the variable V , which can be of type Longint , Real and Byte or any enumerated type.

What is a Pascal string?

Pascal string is a sequence of characters with optional size specification. It may contain numeric characters, letters, blanks, special characters or a combination of all of them.


1 Answers

The 'copy' node generator code is in inline_copy function of pinline.pas of FPC sources. Only for dynamic arrays variants 1 and 3 are valid (which generates code to pass -1 for second and third parameters to fpc_dynarray_copy in case of variant 3). For all other cases (ansi string, wide string, unicode string, char(*) and short string) 3 parameters are required (compiler generates a call to one of the copy functions (e.g. fpc_ansistr_copy in astrings.pas) without checking parameters, since the called function has no overloads or default parameters an exact match of parameters is required). No switches/directives involved.

(*) This one is a bit weird, it returns a shortstring of either itself or ''.

like image 74
Sertac Akyuz Avatar answered Oct 13 '22 13:10

Sertac Akyuz