Similar/Follow-up to this question: Syntax to define a Block that takes a Block and returns a Block in Objective-C
I understand that this wouldn't be something that I would want to do but I want to understand why I can't use a single typedef to define:
typedef void (^XYZSimpleBlock)(void);
typedef XYZSimpleBlock (^ComplexBlock)(void);
Why is the above valid but this is not valid?
typedef void(^)(void) (^ComplexBlock)(void);
If I go by a similar answer I found I can try and parse it like a compiler but I am a bad compiler.
Following C's left-right-rule wouldn't the first identifier be ComplexBlock
?
typedef void(^)(void) (^ComplexBlock)(void);
// parser reads left right and finds ComplexBlock first
Then it would go right and find the close of the declaration, then left until it find the caret, then right to interpret the parameters list.
That brings us to
typedef void(^)(void) (^ComplexBlock)(void);
// | unhandled |compiled/interpreted|
What is happening at this point that it can't read the void(^)(void)
as a return type?
The thing that's confusing to me is that using a typedef is basically just a #define
so shouldn't it be basically the same as above?
typedef void (^XYZSimpleBlock)(void);
same as:
void(^)(void)
so:
typedef XYZSimpleBlock (^ComplexBlock)(void);
should be the same as:
typedef void(^)(void) (^ComplexBlock)(void);
I'm missing something here...