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?
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.
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.
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 ''.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With