65264a58a43ba0b3891c85448cbe8f90c089ae38
[gnulib.git] / m4 / uintptr_t.m4
1 # uintptr_t.m4 serial 3
2
3 # Copyright (C) 2004 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
7
8 # Written by Paul Eggert.
9
10 AC_DEFUN([gl_AC_TYPE_UINTPTR_T],
11 [
12   AC_CACHE_CHECK([for uintptr_t], gl_cv_c_uintptr_t,
13     [gl_cv_c_uintptr_t=no
14      for ac_type in "uintptr_t" "unsigned int" \
15          "unsigned long int" "unsigned long long int"; do
16        AC_COMPILE_IFELSE(
17          [AC_LANG_BOOL_COMPILE_TRY(
18             [AC_INCLUDES_DEFAULT],
19             [[sizeof (void *) <= sizeof (uintptr_t)]])],
20          [gl_cv_c_uintptr_t=$ac_type])
21        test $gl_cv_c_uintptr_t != no && break
22      done])
23   case $gl_cv_c_uintptr_t in
24   no|uintptr_t) ;;
25   *)
26     AC_DEFINE_UNQUOTED(uintptr_t, $gl_cv_c_uintptr_t,
27       [Define to the type of a unsigned integer type wide enough to
28        hold a pointer, if such a type exists.])
29     ;;
30   esac
31
32   dnl Check whether UINTPTR_MAX is defined, not whether it has the
33   dnl right value.  Alas, Solaris 8 defines it to empty!
34   dnl Applications should use (uintptr_t) -1 rather than UINTPTR_MAX.
35   AC_CACHE_CHECK([for UINTPTR_MAX], gl_cv_c_uintptr_max,
36     [AC_COMPILE_IFELSE(
37        [AC_LANG_PROGRAM(
38           [AC_INCLUDES_DEFAULT],
39           [[#ifndef UINTPTR_MAX
40              error: UINTPTR_MAX is not defined.
41             #endif]])],
42        [gl_cv_c_uintptr_max=yes],
43        [gl_cv_c_uintptr_max=no])])
44   case $gl_cv_c_uintptr_max,$gl_cv_c_uintptr_t in
45   yes,*) ;;
46   *,no) ;;
47   *)
48     AC_DEFINE(UINTPTR_MAX, ((uintptr_t) -1),
49       [Define to its maximum value if an unsigned integer type wide enough
50        to hold a pointer exists and the standard includes do not define
51        UINTPTR_MAX.])
52     ;;
53   esac
54 ])