Created
December 5, 2015 19:14
-
-
Save b4284/cbdf993bf95c7f93a0ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <libtcc.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| void gen_addx(char *s, int x) { | |
| sprintf(s, "\ | |
| int addx(int y) { \ | |
| return (%d + y); \ | |
| }", x); | |
| } | |
| int main() { | |
| char prog_str[100]; | |
| gen_addx(prog_str, 5); | |
| TCCState *state = tcc_new(); | |
| tcc_compile_string(state, prog_str); | |
| int func_size = tcc_relocate(state, NULL); | |
| int (*addx)(int) = malloc(func_size); | |
| int q = tcc_relocate(state, addx); | |
| printf("%d\n", addx(7)); | |
| free(addx); | |
| tcc_delete(state); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment