Emil Jerabek wrote:
Peter N Lewis wrote:
It seems that const parameters of string types are passed by value, eg:
program peterT4;
type Str = String(1000);
var gs: Str;
procedure Doit( const s: Str ); begin if @s = @gs then begin WriteLn( 'OK' ); end else begin WriteLn( 'failed' ); end; end;
begin Doit( gs ); end.
fails.
I checked the code and it definitely looks like it is doing a copy.
I use a lot of long strings (2500) and so this seems like a serious problem to me...
Thanks, Peter.
Const parameters may be passed by value or by reference at compiler's discretion. Use protected var to guarantee pass by reference.
Or CONST VAR parameters, in next gpc release. Still - one would expect that gpc chooses the most efficient calling mechanism for each type, by value for small parameters and by reference for large parameters. In fact that is what gpc does for types other than strings (at least when I test it on Mac OS X).
Regards,
Adriaan van Os