[fpc-devel] Parameters must match exactly?
"Vinzent Höfler"
JeLlyFish.software at gmx.net
Wed May 19 03:35:31 CEST 2010
Jonas Maebe <jonas.maebe at elis.ugent.be>:
> On 18 May 2010, at 15:25, Vinzent Höfler wrote:
>
> > But that wasn't the problem. The problem I mean is that:
> >
> > procedure p (out c : tc2)
> > begin
> > c := tc3.create;
> > end;
> >
> > var
> > c1 : tc1;
> >
> > begin
> > p(c1);
> > end.
> >
> > seems not to be allowed anymore.
>
> I guess you mean tc2.create instead of tc3.create.
No, tc3, where tc3 is an descendant of tc2.
> You're correct that
> this is no longer accepted by FPC (nor is it accepted by Kylix). And
> if you don't abuse "out" parameters as "var" parameters (although I'm
> quite sure there's plenty of code out there that does this -- we've
> also had issues with that in the compiler source itself), I also do
> not immediately see how the above could be dangerous.
Ok, at least we're on the same page here, then.
> Then again, for
> some 10 or more years nobody thought of how the old behaviour allowed
> subverting the complete type checking model of the compiler either
> (which is why "useless restriction from Delphi" probably wasn't
> implemented initially).
Well, wouldn't it be more precise, instead of disallowing "non-matching" out-parameters, issue a warning if the "out" parameter is read before written the first time instead? The compiler should issue a "possibly uninitialized" warning, anyway. ;)
(I'll get slapped again, but in Ada83 "out" parameters were write-only, even inside the procedure, but this restriction was dropped in Ada95, because it felt to awkward. No need to make the same mistake again.)
As several people (including me) pointed out, using "out" parameters for class hierarchies does have its usages.
> > BTW, I still can not follow the argument of that "out" parameters
> > need finalization.
>
> It does not apply in the case of classes.
Ok, I would have thought so, too, but the impression was made that it applies here, also. Thanks for clarifying that.
Vinzent.
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
More information about the fpc-devel
mailing list