[fpc-pascal] Passing nested procs out?

Ryan Joseph ryan at thealchemistguild.com
Thu Nov 15 09:46:19 CET 2018


Is passing nested procs outside of the calling scope relying on undefined behavior? It doesn’t seem like this should be allowed.

===========================

{$modeswitch nestedprocvars}

program test;
type
	TCallback = procedure (i: integer) is nested;


function DoTest: TCallback;
var
	context: integer = 0;

	procedure Process(x: integer);
	begin
		context += x;
		writeln(x,' ',context);
	end;
begin
	result := @Process;
end;

var
	c: TCallback;
begin
	c := DoTest(20);
	c(1);
end.


Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list