home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE50.TAR / mbase / src / struct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-02  |  2.6 KB  |  108 lines

  1. /*
  2.  * METALBASE 5.0
  3.  *
  4.  * Released October 1st, 1992 by Huan-Ti [ richid@owlnet.rice.edu ]
  5.  *                                       [ t-richj@microsoft.com ]
  6.  */
  7.  
  8. #ifdef MSDOS
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #endif
  12.  
  13. struct              /* MP_OPTS: -o=str */
  14.  { char   a[13];
  15.    long   b;
  16.    char   c[7];
  17.    double d;
  18.    char   e[3];
  19.  } test;
  20.  
  21. #define STDPOS(x) x-(char*)&test
  22. #define CHRPOS(x) (char *)&x-(char *)&test
  23.  
  24. /*
  25.  * In general:
  26.  *
  27.  * STRUCT_1 -- SunOS 4, DECStation/ULTRIX
  28.  *
  29.  * STRUCT_2 -- COHERENT, DOS/Zortec C
  30.  *
  31.  * STRUCT_3 -- SunOS 3, Xenix
  32.  *
  33.  * STRUCT_4 -- DOS/Microsoft C, Mac Programmers' Workshop
  34.  *
  35.  */
  36.  
  37. int match_1 = 0;  /* Incremented 1 for each that matches */
  38. int match_2 = 0;  /* Incremented 1 for each that matches */
  39. int match_3 = 0;  /* Incremented 1 for each that matches */
  40. int match_4 = 0;  /* Incremented 1 for each that matches */
  41.  
  42. int array[][4] =
  43.    { {  0,    0,    0,    0 },
  44.      { 16,   13,   16,   14 },
  45.      { 20,   17,   20,   18 },
  46.      { 32,   24,   28,   26 },
  47.      { 40,   32,   36,   34 },
  48.      { 48,   35,   40,   38 }  };
  49.  
  50. void
  51. printl (s, n, l)
  52. char   *s;
  53. int        n, l;
  54. {
  55.    printf ("%-6.6s : %2d -- %2d,   %2d,   %2d,   %2d\n", s, n,
  56.             array[l][0], array[l][1], array[l][2], array[l][3]);
  57.  
  58.    if (n == array[l][0])  match_1++;
  59.    if (n == array[l][1])  match_2++;
  60.    if (n == array[l][2])  match_3++;
  61.    if (n == array[l][3])  match_4++;
  62. }
  63.  
  64. void
  65. main ()
  66. {
  67.    int  n;
  68.  
  69.    printf ("\n");
  70.    printf ("        REAL  STR1  STR2  STR3  STR4\n");
  71.    printf ("        ----  ----  ----  ----  ----\n");
  72.    printl ("test.a", STDPOS(test.a), 0);
  73.    printl ("test.b", CHRPOS(test.b), 1);
  74.    printl ("test.c", STDPOS(test.c), 2);
  75.    printl ("test.d", CHRPOS(test.d), 3);
  76.    printl ("test.e", STDPOS(test.e), 4);
  77.    printl ("size  ", sizeof(test),   5);
  78.    printf ("\n");
  79.  
  80.    n = 0;
  81.    if (match_1 == 6)  n |= 0x01;
  82.    if (match_2 == 6)  n |= 0x02;
  83.    if (match_3 == 6)  n |= 0x04;
  84.    if (match_4 == 6)  n |= 0x08;
  85.  
  86.    if (! n || (n != 1 && n != 2 && n != 4 && n != 8))
  87.       {
  88.       printf ("Your compiler does not match any of the expected values.\n");
  89.       printf ("Look in your compiler manuals for any compile-time switches\n");
  90.       printf ("which control structure-packing; add such a switch to\n");
  91.       printf ("CFLAGS in the makefile, and recompile struct.\n");
  92.       n = 0;
  93.       }
  94.    else
  95.       {
  96.       if (n == 4)  n = 3;
  97.       if (n == 8)  n = 4;
  98.  
  99.       printf("For your compiler, you need to #define STRUCT_%d when\n", n);
  100.       printf("compiling the library... do this by setting -DSTRUCT_%d in\n",n);
  101.       printf("the makefile.\n");
  102.       }
  103.    printf ("\n");
  104.  
  105.    exit (0);
  106. }
  107.  
  108.