Hello,
Here's the code:
procedure dump(const a: array of string);
var
i : integer;
begin
for i:=0 to length(a)-1 do
writeln(a[i]);
end;
const
fast : array [0..2] of string = ('aa','bb','cc');
begin
dump(['a','b','c']);
dump(fast);
end.The first call to dump(), where the array is passed as "inline" declaration, consists of building of an open array with string constants:
movl $_$PROGRAM$_Ld4,%eax
movl %eax,-12(%ebp)
movl $_$PROGRAM$_Ld5,%eax
movl %eax,-8(%ebp)
movl $_$PROGRAM$_Ld6,%eax
movl %eax,-4(%ebp)
leal -12(%ebp),%eax
movl $2,%edx
call P$PROGRAM_DUMP$array_of_ANSISTRING
the second call, is however just passing a reference to the constant of the open array ("fast")
movl $TC_P$PROGRAM_FAST,%eax
movl $2,%edx
call P$PROGRAM_DUMP$array_of_ANSISTRING
Question: would it be reasonable for the compiler to turn an inline declaration of ['a','b','c'], into a constant implicitly? That would save some instructions to make a call
dump(['a','b','c']);is there an optimization switch for that already?
thanks,
Dmitry
