Skip to content

Instantly share code, notes, and snippets.

@theoknock
Created April 28, 2022 23:40
Show Gist options
  • Save theoknock/29a9f156c28441ae7019ce8ca0174b70 to your computer and use it in GitHub Desktop.
Save theoknock/29a9f156c28441ae7019ce8ca0174b70 to your computer and use it in GitHub Desktop.
A block and its parameter value with one pointer
const float (^(^blk)(float))(void) = ^ (float f) {
return ^ (float f) {
return ^ float {
return f;
};
}(f);
};
const float(^blk_param)(void) = blk(1.0);
printf("blk_param() == %f\n", blk_param());
const void * (^ const __strong blk_param_t)(typeof(const float (^)(void))) = ^ (typeof(const float (^)(void)) blk_param) {
return Block_copy((const void *)CFBridgingRetain(blk_param));
};
const void * blk_ptr = blk_param_t(blk_param);
const float (^(^ const __strong blk_param_)(const void *))(void) = ^ (const void * blk_param_t) {
return (typeof(const float (^)(void)))CFBridgingRelease(blk_param_t);
};
printf("blk_param_() == %f\n", (blk_param_(blk_ptr))());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment