I want to declare a block type which take one parameter that is the same block type. It's just like this:
typedef void (^BlockInBlock) (BlockInBlock block);
I know the declaration is not valid. But I wonder if there is any possible way to implement recursive block which take just one parameter that is the same block type.
I'm trying finding a way to implement aspect-oriented programming (AOP) in Objective-C using block. Here are my questions about how to implement that.
Further Question 1:
How to implement a variadic function which takes many Blocks I described above and is ended up with nil
, and I could invoke that function with many blocks until meets nil? It would be like this:
@interface NSObject(AOP)
- (void) invokeBlockInBlock:(BlockInBlock) headBlock, ...{
va_list blockList;
va_start(blockList, headBlock);
// Invoke recursive blocks here until the value of va_arg(blockList, BlockInBlock) is nil
// it would be like: block1(self, block2(self, block3(self, block4(...))));
va_end(blockList);
}
@end
Further Question 2:
What if the recursive block has a return value?
Additional Question about C language:
Is it possible to declare a C function which take one parameter that is a C function pointer, and that C function pointer's function also takes another C function pointer?