Distribute allocsa.valgrind.
[gnulib.git] / m4 / uintptr_t.m4
1 # uintptr_t.m4 serial 2
2
3 # Copyright (C) 2004 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 # Written by Paul Eggert.
20
21 AC_DEFUN([gl_AC_TYPE_UINTPTR_T],
22 [
23   AC_CACHE_CHECK([for uintptr_t], gl_cv_c_uintptr_t,
24     [gl_cv_c_uintptr_t=no
25      for ac_type in "uintptr_t" "unsigned int" \
26          "unsigned long int" "unsigned long long int"; do
27        AC_COMPILE_IFELSE(
28          [AC_LANG_BOOL_COMPILE_TRY(
29             [AC_INCLUDES_DEFAULT],
30             [[sizeof (void *) <= sizeof (uintptr_t)]])],
31          [gl_cv_c_uintptr_t=$ac_type])
32        test $gl_cv_c_uintptr_t != no && break
33      done])
34   case $gl_cv_c_uintptr_t in
35   no|uintptr_t) ;;
36   *)
37     AC_DEFINE_UNQUOTED(uintptr_t, $gl_cv_c_uintptr_t,
38       [Define to the type of a unsigned integer type wide enough to
39        hold a pointer, if such a type exists.])
40     ;;
41   esac
42
43   dnl Check whether UINTPTR_MAX is defined, not whether it has the
44   dnl right value.  Alas, Solaris 8 defines it to empty!
45   dnl Applications should use (uintptr_t) -1 rather than UINTPTR_MAX.
46   AC_CACHE_CHECK([for UINTPTR_MAX], gl_cv_c_uintptr_max,
47     [AC_COMPILE_IFELSE(
48        [AC_LANG_PROGRAM(
49           [AC_INCLUDES_DEFAULT],
50           [[#ifndef UINTPTR_MAX
51              error: UINTPTR_MAX is not defined.
52             #endif]])],
53        [gl_cv_c_uintptr_max=yes],
54        [gl_cv_c_uintptr_max=no])])
55   case $gl_cv_c_uintptr_max,$gl_cv_c_uintptr_t in
56   yes,*) ;;
57   *,no) ;;
58   *)
59     AC_DEFINE(UINTPTR_MAX, ((uintptr_t) -1),
60       [Define to its maximum value if an unsigned integer type wide enough
61        to hold a pointer exists and the standard includes do not define
62        UINTPTR_MAX.])
63     ;;
64   esac
65 ])