[fpc-devel] [MacPascal] Blocks support

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Jul 18 11:20:11 CEST 2014


On 16/07/14 14:12, Jonas Maebe wrote:

> I've (locally, not yet in svn) implemented support for blocks in FPC (
> http://en.wikipedia.org/wiki/Blocks_(C_language_extension) ).

I've now committed the initial implementation in the blocks branch on 
svn. As discussed on the fpc-devel list, the syntax has been changed to:

type
   NSArrayEnumeratorBlock = reference to procedure (obj: id; idx: 
NSUInteger; var stop: boolean); cdecl;

The reason is that Delphi already introduced the "reference to" syntax 
for anonymous functions in Pascal. The extra "cdecl;" indicates that 
it's the C-variant of an anonymous function (i.e., a "block").

Apart from supporting global routines, the current implementation also 
already supports assigning the address of a method of a Pascal 
class/object to a block variable (or passing it to a block parameter). 
Nested functions/procedures are not yet supported.


Jonas



More information about the fpc-devel mailing list