[fpc-devel] Compiler bug?
Daniël Mantione
daniel.mantione at freepascal.org
Sun Jan 31 09:30:24 CET 2010
Op Sun, 31 Jan 2010, schreef Paul van Helden:
> Of course.... Thanks Cobines!
>
> I have never used the function name instead of "Result", but of course you
> can. Using () after a function to me seems so C-like and un-Pascallish but it
> works.
>
> But it is things like this that trip up people coming from Delphi, I guess.
> Isn't this a potential improvement to the compiler though: scan for
> overloaded functions before assuming that it is the result value (like Delphi
> does)? (Or warn about overloaded functions without parameters, similar to
> mode objfpc disallowing parameter names that are the same as methods?)
This behaviour is intentional to allow you to read instead of just write
the function result. The incompatibility just affects recursive procedures
without parameters, which seldomly occurs, because normally the
parameters determine the behaviour of the function, and a recursive
function without parameters would prevent you writing a mechanism that
makes the recursive function terminate.
Only if the behaviour of the recursive function is controller by global
variables, then you can actually write a recursive function without
parameters. Because this is so seldom, and the desire to read from the
function result is extremely common, there is a strong case for this
behaviour.
Indeed Borland did invent "result" as a method to read from the
function result, so FPC had to support that too.
Daniël
More information about the fpc-devel
mailing list