On 17 Jun 2018, at 22:48, Fred Kiefer <fredkie...@gmx.de> wrote:
> 
> I was hoping for someone with a working knowledge of blocks to step in here. 
> But currently I seem to be the only one operating this mailing list :-)
> 
> If you have a look in the file Tests/base/NSArray/blocks.m you will find 
> examples on how to write an NSBlock for a compiler that supports it. A very 
> simple one would be this:
> ^() { return YES; }
> 
> You should also be able to simulate blocks with gcc, but I am not sure how to 
> do this :-(

You can, in theory, simulate blocks with any C compiler, but in practice it’s 
too hard. A block is a structure that contains pointers to other structures 
that describe all of the captured variables and how to copy them.  For anything 
beyond a simple function written as a block, the compiler is generating a load 
of helper code for copying the captures.

The GSBlock stuff allows a legacy compiler to *call* blocks (by casting them to 
a compatible structure type and calling the invoke function with a pointer to 
the struct as the first argument) but it doesn’t make any attempt to allow 
compilers for pre-2007 dialects of Objective-C to generate blocks.  The logic 
in the compiler for doing so is several hundred lines of code and integrates 
with understanding of object lifetimes - replicating this in C macros is not 
feasible.

David


_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to