Skip to content

Instantly share code, notes, and snippets.

@oliverhu
Created March 24, 2017 00:47
Show Gist options
  • Save oliverhu/93ac8a39ccd0250b4be39359ab7934b0 to your computer and use it in GitHub Desktop.
Save oliverhu/93ac8a39ccd0250b4be39359ab7934b0 to your computer and use it in GitHub Desktop.
//
// main.m
// BlockPlayground
//
// Created by Keqiu Hu on 3/20/17.
// Copyright © 2017 LinkedIn. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef void (^block_t)(void);
void func(block_t block) {
if (block) {
block();
}
}
void foo(int param) {
int x0 = param;
block_t block = ^{
int y0 = x0;
printf("Hello block 1\n");
printf("Address of auto y0: %p\n", &y0);
printf("Address of captured x0: %p\n", &x0);
};
func(block);
// func(^{
// int y0 = x0;
// printf("Hello block 1\n");
// printf("Address of auto y0: %p\n", &y0);
// printf("Address of captured x0: %p\n", &x0);
// });
}
int main(int argc, const char * argv[]) {
foo(10);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment