Created
May 26, 2014 23:35
-
-
Save loriopatrick/2594fd21a09602d60fd5 to your computer and use it in GitHub Desktop.
C is awesome!
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> | |
#define call(VAR, METHOD, ...) (VAR)->METHOD(VAR, __VA_ARGS__) | |
#define with(TYPE, NAME, VALUE, BODY) {TYPE NAME = VALUE; BODY free(NAME);} | |
void flyImpl(void* rocket, int x_fore, int y_fore) { | |
printf("Applying force (%i, %i)\n", x_fore, y_fore); | |
} | |
typedef struct { | |
void (*fly)(void*, int, int); | |
} Rocket; | |
int main(int argc, char const *argv[]){ | |
with(char*, test, NULL, { | |
asprintf(&test, "My name is %s", "Macro Lover"); | |
printf("test said: \"%s\"\n", test); | |
}); | |
Rocket rocket; | |
rocket.fly = flyImpl; | |
call(&rocket, fly, 2, 3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment