Created
December 17, 2009 11:28
-
-
Save fourdollars/258690 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
/* Cascaded function calls in C */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct Object Object; | |
struct Object { | |
Object* (*foo)(Object*); | |
}; | |
static Object* foo(Object* obj) | |
{ | |
printf("Hello World!\n"); | |
return obj; | |
} | |
static Object* createObject(void) | |
{ | |
Object* obj = (Object*) malloc(sizeof(Object)); | |
obj->foo = foo; | |
return obj; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
Object* obj = createObject(); | |
obj->foo(obj)->foo(obj)->foo(obj)->foo(obj); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment