strcmp, which returns 0 for a match, resulting in the assignment of c to a third value.// clang blocks.m -o prog -framework Foundation -fobjc-gc-only
#import <Foundation/Foundation.h>
typedef int (^A) (int x);
typedef void (^B) ();
int main(int argc, char * argv[]){
int y = 7;
__block char *c = "abc\0";
printf("initial: %s\n", c);
const char *c2 = "def\0";
A a = ^(int x) {
c = (char *) c2;
return x*y;
};
B b = ^() {
if (!(strcmp(c,c2))) {
c = "ghi\0";
}
};
printf("a(2) returns: %i\n", a(2));
printf("before b(): %s\n", c);
b();
printf("after b(): %s\n", c);
return 0;
} |
Output:
> ./prog initial: abc a(2) returns: 14 before b(): def after b(): ghi |