dnl @synopsis AC_COMPILE_CHECK_SIZEOF(TYPE [, HEADERS [, EXTRA_SIZES...]]) dnl dnl This macro checks for the size of TYPE using compile checks, not dnl run checks. You can supply extra HEADERS to look into. the check dnl will cycle through 1 2 4 8 16 and any EXTRA_SIZES the user dnl supplies. If a match is found, it will #define SIZEOF_`TYPE' to dnl that value. Otherwise it will emit a configure time error dnl indicating the size of the type could not be determined. dnl dnl The trick is that C will not allow duplicate case labels. While dnl this is valid C code: dnl dnl switch (0) case 0: case 1:; dnl dnl The following is not: dnl dnl switch (0) case 0: case 0:; dnl dnl Thus, the AC_TRY_COMPILE will fail if the currently tried size dnl does not match. dnl dnl Here is an example skeleton configure.in script, demonstrating the dnl macro's usage: dnl dnl AC_PROG_CC dnl AC_CHECK_HEADERS(stddef.h unistd.h) dnl AC_TYPE_SIZE_T dnl AC_CHECK_TYPE(ssize_t, int) dnl dnl headers='#ifdef HAVE_STDDEF_H dnl #include dnl #endif dnl #ifdef HAVE_UNISTD_H dnl #include dnl #endif dnl ' dnl dnl AC_COMPILE_CHECK_SIZEOF(char) dnl AC_COMPILE_CHECK_SIZEOF(short) dnl AC_COMPILE_CHECK_SIZEOF(int) dnl AC_COMPILE_CHECK_SIZEOF(long) dnl AC_COMPILE_CHECK_SIZEOF(unsigned char *) dnl AC_COMPILE_CHECK_SIZEOF(void *) dnl AC_COMPILE_CHECK_SIZEOF(size_t, $headers) dnl AC_COMPILE_CHECK_SIZEOF(ssize_t, $headers) dnl AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers) dnl AC_COMPILE_CHECK_SIZEOF(off_t, $headers) dnl dnl @author Kaveh Ghazi dnl @version $Id: ac_compile_check_sizeof.m4,v 1.1.1.1 2001/07/26 00:46 ac-archive-0.5.39 $ dnl AC_DEFUN([AC_COMPILE_CHECK_SIZEOF], [changequote(<<, >>)dnl dnl The name to #define. define(<>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl dnl The cache variable name. define(<>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl changequote([, ])dnl AC_MSG_CHECKING(size of $1) AC_CACHE_VAL(AC_CV_NAME, [for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence. AC_TRY_COMPILE([#include "confdefs.h" #include $2 ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size) if test x$AC_CV_NAME != x ; then break; fi done ]) if test x$AC_CV_NAME = x ; then AC_MSG_ERROR([cannot determine a size for $1]) fi AC_MSG_RESULT($AC_CV_NAME) AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1]) undefine([AC_TYPE_NAME])dnl undefine([AC_CV_NAME])dnl ])