1 dnl /usr/share/aclocal/ac-archive-cvs/ac_compile_check_sizeof.m4
2 dnl @synopsis AC_COMPILE_CHECK_SIZEOF(TYPE [, HEADERS [, EXTRA_SIZES...]])
4 dnl This macro checks for the size of TYPE using compile checks, not
5 dnl run checks. You can supply extra HEADERS to look into. the check
6 dnl will cycle through 1 2 4 8 16 and any EXTRA_SIZES the user
7 dnl supplies. If a match is found, it will #define SIZEOF_`TYPE' to
8 dnl that value. Otherwise it will emit a configure time error
9 dnl indicating the size of the type could not be determined.
11 dnl The trick is that C will not allow duplicate case labels. While
12 dnl this is valid C code:
14 dnl switch (0) case 0: case 1:;
16 dnl The following is not:
18 dnl switch (0) case 0: case 0:;
20 dnl Thus, the AC_TRY_COMPILE will fail if the currently tried size does
23 dnl Here is an example skeleton configure.in script, demonstrating the
27 dnl AC_CHECK_HEADERS(stddef.h unistd.h)
29 dnl AC_CHECK_TYPE(ssize_t, int)
31 dnl headers='#ifdef HAVE_STDDEF_H
32 dnl #include <stddef.h>
34 dnl #ifdef HAVE_UNISTD_H
35 dnl #include <unistd.h>
39 dnl AC_COMPILE_CHECK_SIZEOF(char)
40 dnl AC_COMPILE_CHECK_SIZEOF(short)
41 dnl AC_COMPILE_CHECK_SIZEOF(int)
42 dnl AC_COMPILE_CHECK_SIZEOF(long)
43 dnl AC_COMPILE_CHECK_SIZEOF(unsigned char *)
44 dnl AC_COMPILE_CHECK_SIZEOF(void *)
45 dnl AC_COMPILE_CHECK_SIZEOF(size_t, $headers)
46 dnl AC_COMPILE_CHECK_SIZEOF(ssize_t, $headers)
47 dnl AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
48 dnl AC_COMPILE_CHECK_SIZEOF(off_t, $headers)
51 dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu>
52 dnl @version 2000-07-19
53 dnl @license GPLWithACException
55 AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
56 [changequote(<<, >>)dnl
57 dnl The name to #define.
58 define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
59 dnl The cache variable name.
60 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
62 AC_MSG_CHECKING(size of $1)
63 AC_CACHE_VAL(AC_CV_NAME,
64 [for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence.
65 AC_TRY_COMPILE([#include "confdefs.h"
66 #include <sys/types.h>
68 ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size)
69 if test x$AC_CV_NAME != x ; then break; fi
72 if test x$AC_CV_NAME = x ; then
73 AC_MSG_ERROR([cannot determine a size for $1])
75 AC_MSG_RESULT($AC_CV_NAME)
76 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1])
77 undefine([AC_TYPE_NAME])dnl
78 undefine([AC_CV_NAME])dnl