Hi GPC Crew,
I just hit something I do not really understand in the way GPC passes parameters to procedures. The following sample program:
Program ParamTest; Var S40 : String(40); I : Integer;
Procedure TstParams(S : String; IL : Integer); Begin WriteLn('Before: S=', S, ' IL=', IL); S := S + 'BBB'; { Using Concat() does the same } IL := IL + 4; WriteLn('After: S=', S, ' IL=', IL); End;
Begin S40 := 'AAA'; I := 4; TstParams(S40, I); End.
Produces the following output: Before: S=AAA IL=4 After: S=AAA IL=8
How come the string cannot be modified inside of the procedure (without impacting the global string) but the integer can? Until now, my understanding of the parameters passing mechanism was that when you pass a parameter by value, the procedure uses a local copy of it, and this copy may be modified locally. This mechanism seems to work for integers but not for strings! However, if the string modification is somewhat "illegal" at least GPC could issue a compilation warning.
I would be interested to understand better how this works, because this behavior causes bugs in the programs I am porting from SUN Pascal and perhaps in ways I don't see as clearly as in this example.
Thanks
Pascal Viandier pascal@accovia.com