Created
April 4, 2012 11:56
-
-
Save alexdrone/2300598 to your computer and use it in GitHub Desktop.
Snippet of C with blocks
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
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct _Object{ | |
const char *objectClass; | |
int objectId; | |
int (^isEqualToObject) (void *other); | |
} Object; | |
void init(void *obj) | |
{ | |
__block Object *o = obj; | |
o->objectId = 0; | |
o->objectClass = "Object"; | |
o->isEqualToObject = ^(void *other) { | |
if (other == obj) return 1; | |
else return 0; | |
}; | |
} | |
int main() | |
{ | |
Object *object = malloc(sizeof(Object)); | |
init(object); | |
printf("%d", object->isEqualToObject(object)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment