home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / common / infer.c < prev    next >
C/C++ Source or Header  |  2001-12-12  |  816b  |  32 lines

  1. /*
  2.  *  infer.c -- generate definitions reflecting present hardware architecture
  3.  *
  4.  *  Inspired by mail from Christian Hudon.
  5.  */
  6.  
  7. #include <assert.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10.  
  11. typedef struct {
  12.    char c;
  13.    double d;
  14.    } tstruct;
  15.  
  16. static long atdepth(int n) {
  17.    return n <= 1 ? (long)&n : atdepth(n - 1);
  18.    }
  19.  
  20. int main(int argc, char *argv[]) {
  21.    assert (-1 == (signed char)0xFF);        /* chars must be 8 bits */
  22.    assert (sizeof(void*) == sizeof(long));    /* these must be the same */
  23.    printf("/* generated by infer.c */\n");
  24.    printf("#define IntBits %d\n", 8 * sizeof(int));
  25.    printf("#define WordBits %d\n", 8 * sizeof(void *));
  26.    if (offsetof(tstruct, d) > sizeof(void *))
  27.       printf("#define Double\n");
  28.    if (atdepth(2) > atdepth(1))
  29.       printf("#define UpStack\n");
  30.    return 0;
  31.    }
  32.