[fpc-devel]Nested function as argument for TList.Sort

Pedro Lopez-Cabanillas plcl at telefonica.net
Sun Nov 30 02:29:43 CET 2003


Peter Vreman wrote:
> > Peter Vreman wrote:
> > [...]
> >
> >> > This is bad coding imho and works in Delphi only "by accident" because
> >> > Delphi uses register calling conventions. Or are I'am wrong and sort
> >> > expects a local procedure?
> >>
> >> The compiler should give an error. It is bad coding and only a
> >> "undocumented feature" of delphi register calling that makes it working.
> >> Because there is no full description of the register calling in delphi,
> >> like how does it insert the self,parameter return or parent framepointer
> >> parameters.
> >
> > I don't fully agree with both comments. Why is it bad code? Is this code
> > violating some rule about scope, or any other rule or Pascal language
> > convention? If not, the compiler is right here, eating this code without
> > a single warning.
>
> The the nested procedure is only valid when called from the parent
> procedure. TList.Sort() is a different procedure that does not know if a
> giving procedure is a nested procedure or not. The correct fix for the
> compiler is to give an error. Relying on the behaviour of calling
> conventions is very bad. Also the code won't work on sparc/ppc which have
> a different calling convention.

Of course, if the compiler doesn't support this feature, because the internal  
handling of function calls, a compiler error message is better than a program 
crash.

But I was talking about Pascal language conventions. Instead of my code 
snippet, you can refer to the document "Extended Pascal", ISO-10206, chapter 
6.11.6, examples 6-9. It's available here (among other places):
http://www.pascal-central.com/standards.html

And GPC supports this feature, see:
http://www.gnu-pascal.de/demos/iteratordemo.pas

Regards,
Pedro

-- 
ALSA Library Bindings for Pascal
http://alsapas.alturl.com





More information about the fpc-devel mailing list