/* type_s16.h Define 16-bit integer data types, basec on user-supplied options of compiler-supplied #defines if available. We pretty much have to assume that short is 16-bit. There is a remote chance that someone might try to compile my code for an 8/16-bit microcontroller, in which case short might be 8-bit. Notes about the 32-bit type are in type_s32.h */ /* First check user-supplied options */ #ifdef SHORT_IS_S16 typedef signed short s16; typedef unsigned short u16; # define HAVE_S16 #elif INT_IS_S16 typedef signed int s16; typedef unsigned int u16; # define HAVE_S16 #endif /* If our compiler is GCC, short is almost certainly 16-bit. */ #ifdef __GNUC__ typedef signed short s16; typedef unsigned short u16; # define HAVE_S16 #endif /* Defaults */ #ifndef HAVE_S16 typedef signed short s16; typedef unsigned short u16; # define HAVE_S16 #endif /* This macro provides code that you can use at runtime (e.g. at the beginning of your main) to make sure s16 is actually 16 bits. It assumes is already included. We don't include stdio for you because perhaps you don't want to use this macro. */ #ifndef TYPE_S16_CHECK_SIZE # define TYPE_S16_CHECK_SIZE(procname) \ if (sizeof(s16) != 2) { \ printf("%s: s16 is not 2 bytes (got %d).\n", \ (procname), (int) sizeof(s16)); \ if (sizeof(short) == 2) { \ printf( \ " To fix this error, recompile with the flag -DSHORT_IS_S16\n"); \ } else if (sizeof(int) == 2) { \ printf( \ " To fix this error, recompile with the flag -DINT_IS_S16\n"); \ } else { \ printf( \ " (presently, sizeof(short)==%d and sizeof(int)==%d)\n", \ (int) sizeof(short), (int) sizeof(int)); \ } \ exit(-1); \ } #endif