[lazarus] classesh.inc change required
Marc Weustink
Marc.Weustink at cuperus.nl
Thu Dec 23 07:42:22 EST 1999
+ From: Florian Klaempfl [mailto:Florian.Klaempfl at gmx.de]
<snip>
+
+ One important point is overloading, consider the following:
+
+ type
+ tf = function : integer;
+
+ function f : integer;
+ procedure p(i : integer);
+ procedure p(f : tf);
+
+ In Delphi mode you would write:
+
+ p(f);
+
+ but what should the compiler do? Call f and using the first
+ version p or
+ using the second one and passing the address of f?
As I wrote earlier this thread:
It is pretty clear if you take the following rule into
account:
If a function/procedure matches the type of the var,
the adress of this function/procedure is passed.
In all other cases the evaluation of function/procedure(?).
So in your example procedure p(f : tf) gets called.
Thats the same Delphi does. If you want to get f evaluated you should call p
like: p((f)) so f gets evaluated first (bracket rule). Its still clear.
+ In FPC mode it's clear:
+ p(f);
+ means calling f and using the integer version of p
+ while
+ p(@f);
+ calls the second one
+ It even works if you've a third version of p:
+ procedure p(p : pointer);
+
+ p(@f);
+ still calls the second version because the last one would
+ require an (implicit) type cast,
+ if you
+ want to call the last one you have to write
+
+ p(pointer(@f));
??? That is IMHO dependig of the result of the @ operator is
typed or untyped (depending on the T derective)
if the @ result is typed, the second form should be called otherwise the
third (since it is untyped and thus a Pointer).
If not so then the compiler is IMHO inconsequent (and inclear)
Marc
More information about the Lazarus
mailing list