Advertisement
Guest User

Long double vs Double

a guest
Sep 6th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #include "libtcc.h"
  6.  
  7. char my_program[] =
  8. "int GetLongDoubleSize(int n)\n"
  9. "{\n"
  10. "    return sizeof(long double);\n"
  11. "}\n"
  12. "int GetDoubleSize(int n)\n"
  13. "{\n"
  14. "    return sizeof(double);\n"
  15. "}\n";
  16.  
  17.  
  18. int main(int argc, char **argv)
  19. {
  20.     TCCState *s;
  21.     int (*func)(int);
  22.  
  23.     s = tcc_new();
  24.     if (!s) {
  25.         fprintf(stderr, "Could not create tcc state\n");
  26.         exit(1);
  27.     }
  28.  
  29.     /* if tcclib.h and libtcc1.a are not installed, where can we find them */
  30.     if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
  31.         tcc_set_lib_path(s, argv[1]+9);
  32.  
  33.     /* MUST BE CALLED before any compilation */
  34.     tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
  35.  
  36.     if (tcc_compile_string(s, my_program) == -1)
  37.         return 1;
  38.  
  39.     /* relocate the code */
  40.     if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
  41.         return 1;
  42.  
  43.     /* get entry symbol */
  44.     printf("----- tcc compiled 'char program': \n");
  45.  
  46.     func = tcc_get_symbol(s, "GetLongDoubleSize");
  47.     printf("Long Double size: %d\n",func(0));
  48.  
  49.     func = tcc_get_symbol(s, "GetDoubleSize");
  50.     printf("Double size: %d\n",func(0));
  51.  
  52.  
  53.     printf("----- gcc compiled functions: \n");
  54.  
  55.     printf("gcc Long Double size: %d\n",sizeof(long double));
  56.     printf("gcc Double size: %d\n",sizeof(double));
  57.  
  58.     /* delete the state */
  59.     tcc_delete(s);
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement