What does "long long (^blockFun)() = (long long (^)())moreBlockFun" mean and do?
I am trying to learn and use Blocks effectively.
On the web, I have come across this code:
long long (^blockFun)() = (long long (^)())moreBlockFun;
I think it is trying to create a block that expects a block that returns a long and I think it is doing some casting somewh开发者_StackOverflow社区ere too.
It's a block type cast and yes, the syntax isn't great. We assume that moreBlockFun
is a block that takes no parameters, and returns something with a sensible cast to long long - this type signature is written long long (^)()
. So we create a new local name for that block called blockFun
, with the syntax long long (^blockFun)()
, and perform the cast.
It's a mess mostly inherited from function pointer type notation, which virtually every C programmer has to lookup around 482 times before they remember it. You're not alone!
精彩评论