-
-
Save oliverhu/93ac8a39ccd0250b4be39359ab7934b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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