Block相关宏定义

以下宏定义摘抄自:GUNStep

#define BLOCK_SCOPE __block

/**
 * Defines a block type.  Will work whether or not the compiler natively
 * supports blocks.
 */
#define DEFINE_BLOCK_TYPE(name, retTy, argTys, ...) \
typedef retTy(^name)(argTys, ## __VA_ARGS__)

#define DEFINE_BLOCK_TYPE_NO_ARGS(name, retTy) \
typedef retTy(^name)()


/**
 * Calls a block.  Works irrespective of whether the compiler supports blocks.
 */
#define CALL_BLOCK(block, args, ...) block(args, ## __VA_ARGS__)

/**
 * Calls a block without arguments.
 */
#define CALL_BLOCK_NO_ARGS(block) block()


#define DEFINE_BLOCK_TYPE_STRUCT(name, retTy, argTys, ...) \
typedef struct {\
void *isa;\
int flags;\
int reserved;\
retTy (*invoke)(void*, argTys, ## __VA_ARGS__);\
} *name

#define DEFINE_BLOCK_TYPE_NO_ARGS_STRUCT(name, retTy) \
typedef struct {\
void *isa;\
int flags;\
int reserved;\
retTy (*invoke)(void*);\
} *name

#define CALL_BLOCK_STRUCT(block, args, ...) block->invoke(block, args, ## __VA_ARGS__)

#define CALL_BLOCK_NO_ARGS_STRUCT(block) block->invoke(block)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容