mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-12 14:49:33 +02:00

as a parameter and the funcret is also passed as parameter. Because in that case both are pointing to the same memory location git-svn-id: trunk@10159 -
38 lines
734 B
ObjectPascal
38 lines
734 B
ObjectPascal
{$ifdef fpc}{$mode objfpc}{$H+}{$endif}
|
|
|
|
const buf: array[0..5] of char = 'abcdef';
|
|
|
|
function foo(const a: string): string;
|
|
begin
|
|
SetLength(result, 6);
|
|
Move(buf, result[1], sizeof(buf));
|
|
if a <> '1234567890' then
|
|
begin
|
|
writeln('Failed: ', a);
|
|
Halt(1);
|
|
end
|
|
else
|
|
writeln('ok');
|
|
end;
|
|
|
|
procedure test_proc(var a: string);
|
|
var
|
|
s: string;
|
|
begin
|
|
{ Don't call UniqueString(s) here because it makes the compiler assume
|
|
that address of s is taken, and assignment s := foo(s) is not optimized }
|
|
s := a; // refcount=2
|
|
a := 'whatever'; // modify source -> s.refcount becomes 1
|
|
writeln('before: ', s);
|
|
s := foo(s);
|
|
writeln(s);
|
|
end;
|
|
|
|
var
|
|
s: string;
|
|
begin
|
|
s := '1234567890';
|
|
UniqueString(s);
|
|
test_proc(s);
|
|
end.
|