Hi (Frank),
I'm just trying gpc20030209 with gcc 3.2.1 and I've got a new error since the 2.1 build:
"reference parameter passing of variant record selector"
I don't understand what's illegal and the syntax of this error message is hard to understand. I think it means "variant record selector cannot be passed by reference"
I have a variant record where the selector is an enumerated type (eg. true / false). I have a procedure which reads the true / false string from a file and assigns the corresponding enumerated type to the selector. This fails because the selector is passed to my procedure as a VAR parameter. The workaround is to use a temporary variable for the enumerated type in the procedure call, and then copy it to the selector afterwards.
This seems to be just a way of avoiding a previously legal construct in the first place.
Any comment.
PS. I'll look out for the dynamic array change in a future gpc release and let you know how the tests go.
Thanks.
David Wood QinetiQ Farnborough
The Information contained in this E-Mail and any subsequent correspondence is private and is intended solely for the intended recipient(s). For those other than the recipient any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on such information is prohibited and may be unlawful.
Wood David wrote:
Hi (Frank),
I'm just trying gpc20030209 with gcc 3.2.1 and I've got a new error since the 2.1 build:
"reference parameter passing of variant record selector"
I don't understand what's illegal
6.7.3.3:
: An actual variable parameter shall not denote a field that is the selector : of a variantÂÂpart.
I think the reason is for cases such as the following:
program Foo (Output);
procedure Foo (var a, b: Boolean); begin WriteLn (a); b := True; WriteLn (a) end;
type t = record case a: Boolean of False: (b: Boolean); True: () end;
var v: t;
begin v.b := False; v.a := False; Foo (v.a, v.b) end.
Here, the first `WriteLn' would be valid, the second one invalid. Furthermore, the procedure doesn't know about the variant record at all, so it can't easily check it (in an implementation that implements variant checking which GPC doesn't do (yet)). That would mean that *every* reference parameter would have to be checked, in a way that the called routine doesn't even know about. This would be a big overhead (maybe using callbacks for checking etc.) and might be a performance killer.
So it was decided (rightfully IMHO) to not allow such constructs in the first place.
and the syntax of this error message is hard to understand. I think it means "variant record selector cannot be passed by reference"
I'll change it.
The workaround is to use a temporary variable for the enumerated type in the procedure call, and then copy it to the selector afterwards.
This seems to be just a way of avoiding a previously legal construct in the first place.
It was never "legal". GPC just didn't detect it before (like it still misses many other errors).
Frank