Maurice Lombardi wrote:
While recompiling the programs in the demos directory of gpc I found a bug (may be only in the demo program)
factorial.pas: In main program: factorial.pas:45: reference expected, value given factorial.pas:45: invalid type of argument of `ReadStr/Val'
the offending line is
ReadStr (ParamStr (1), n);
It was valid last time I compiled these demo programs.
If I affect ParamStr(1) to a temporary String (or CString with {$X+}) everything is correct.
The problem seems related to the fact that in the doc ReadStr is defined as
procedure ReadStr (const S: String; variables);
There is somewhere written (for parameters passing to C) that const parameters can be either value or reference, depending on compiler convenience.
Yes, but if it's reference, the compiler should convert non-references automatically, using temporary variables where necessary (not here actually, since a temporary variable is already used for the result of ParamStr, anyway).
The note you refer to should be only relevant to those dealing with the low-level calling interface (e.g., for writing interfaces to other languages), and not affect the behaviour from a Pascal point of view.
And also to the discussion on undiscriminated String parameter passing.
That's not relevant, since `ReadStr' doesn't modify the first parameter. (More generally, it's not relevant to any `const'/`protected' parameters for this reason.)
So either change the compiler or the demo programs (there are several occurences of the bug in the demos). But it would be better that such a natural construct work as expected.
Of course. This bug has crept in during my recent attempts to make type checking (including "lvalue" checking) more strict. In this particular instance, it became too strict. It's fixed now. Thanks for the report. (maur10a.pas)
Frank