Skip to content

Instantly share code, notes, and snippets.

@alexdrone
Created April 4, 2012 11:56
Show Gist options
  • Save alexdrone/2300598 to your computer and use it in GitHub Desktop.
Save alexdrone/2300598 to your computer and use it in GitHub Desktop.
Snippet of C with blocks
#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