Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "libtcc.h"
- char my_program[] =
- "int GetLongDoubleSize(int n)\n"
- "{\n"
- " return sizeof(long double);\n"
- "}\n"
- "int GetDoubleSize(int n)\n"
- "{\n"
- " return sizeof(double);\n"
- "}\n";
- int main(int argc, char **argv)
- {
- TCCState *s;
- int (*func)(int);
- s = tcc_new();
- if (!s) {
- fprintf(stderr, "Could not create tcc state\n");
- exit(1);
- }
- /* if tcclib.h and libtcc1.a are not installed, where can we find them */
- if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
- tcc_set_lib_path(s, argv[1]+9);
- /* MUST BE CALLED before any compilation */
- tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
- if (tcc_compile_string(s, my_program) == -1)
- return 1;
- /* relocate the code */
- if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
- return 1;
- /* get entry symbol */
- printf("----- tcc compiled 'char program': \n");
- func = tcc_get_symbol(s, "GetLongDoubleSize");
- printf("Long Double size: %d\n",func(0));
- func = tcc_get_symbol(s, "GetDoubleSize");
- printf("Double size: %d\n",func(0));
- printf("----- gcc compiled functions: \n");
- printf("gcc Long Double size: %d\n",sizeof(long double));
- printf("gcc Double size: %d\n",sizeof(double));
- /* delete the state */
- tcc_delete(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement