klu*_*udg 6 delphi copy freepascal
Delphi允许3个版本的Copy
功能:
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;
Run Code Online (Sandbox Code Playgroud)
FreePascal似乎只编译第一个(3-arg)版本; 对于其他人我有编译时错误
Error: Wrong number of parameters specified for call to "$fpc_ansistr_copy"
Run Code Online (Sandbox Code Playgroud)
我是否遗漏了一些FPC编译器开关或Copy
Free Pascal中没有过载?
'复制'节点生成器代码是FPC源的inline_copy
功能pinline.pas
.仅对于动态数组,变体1和3是有效的(fpc_dynarray_copy
在变体3的情况下,生成代码以传递第二和第三参数的-1 ).对于所有其他情况(ansi字符串,宽字符串,unicode字符串,char(*)和短字符串),需要3个参数(编译器生成对其中一个复制函数(例如fpc_ansistr_copy
in astrings.pas
)的调用而不检查参数,因为被调用函数具有没有重载或默认参数,需要完全匹配参数).没有涉及开关/指令.
(*)这个有点奇怪,它返回自身或'' 的短串.