Why do nil / NULL blocks cause bus errors when run?

前端 未结 4 1069
囚心锁ツ
囚心锁ツ 2020-12-02 06:06

I started using blocks a lot and soon noticed that nil blocks cause bus errors:

typedef void (^SimpleBlock)(void);
SimpleBlock aBlock = nil;
aBlock(); // bus         


        
4条回答
  •  不知归路
    2020-12-02 06:17

    Caveat: I'm no expert in Blocks.

    Blocks are objective-c objects but calling a block is not a message, although you could still try [block retain]ing a nil block or other messages.

    Hopefully, that (and the links) helps.

提交回复
热议问题