Skip to content

Instantly share code, notes, and snippets.

@oliverhu
Created March 20, 2017 22:31
Show Gist options
  • Save oliverhu/7c4a8c23e2912dbd03f6eb63ab39c23c to your computer and use it in GitHub Desktop.
Save oliverhu/7c4a8c23e2912dbd03f6eb63ab39c23c to your computer and use it in GitHub Desktop.
code snippet
//
// 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