Blocks in g++ ?

Martin Uecker muecker@mayn.de
Wed Jun 30 15:43:00 GMT 1999


On Sat, Jun 12, 1999 at 05:55:40PM +0200, Thomas Steffen wrote:

[...]

> a). just a short example what you could do with it:
> 
>    file("somefile.tmp", [ :file | fprintf(file,"sometext"); ] );
> 
> (this is imagining a smalltalk like syntax for blocks). function file()
> would create a file(handle) and pass it as the only parameter to the
> block. after the execution, the file would be closed. 

In GNU-C you can do something like this:

#define closure(rtype, args, code) \
({ \
	rtype __closure args { return code; } \
	&__closure; \
})

...

foo A[N];

qsort(N, closure(int, (int i, int j), compare_foo(A[i], A[j])),
         closure(void, (int i, int j), SWAP(A[i], A[j])));

[...] 

> could be, *i* don't like gc either... BTW, is there a reasonable way
> to do reference counting in C++? so you don't need gc, but don't have
> to worry about destruction objects either?

www.faqs.org -> C++ FAQ

Martin



More information about the Gcc mailing list