[fpc-devel]Nested function as argument for TList.Sort
peter at freepascal.org
Fri Nov 28 07:44:13 CET 2003
> 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
> 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.
More information about the fpc-devel