Passing block parameter that doesn't match signature

前端 未结 3 1513
南笙
南笙 2020-12-31 18:47

I\'m working with a block-based API and stumbled across a scenario where I was passing in a block parameter that had a signature that didn\'t match the typedef\'d parameter

3条回答
  •  臣服心动
    2020-12-31 19:04

    This is a C thing. A function or block prototype with an empty argument list means "the function (or block) takes any arguments you like". If you want to convey that the block should have no arguments, you need to explicitly say so like this:

    typedef void(^MyBlock)(void)
    

    This is largely historical from the days before ANSI when there weren't function prototypes and all function declarations (as opposed to definitions) looked like this:

    some_type function();
    

提交回复
热议问题