+AC_CHECK_SIZEOF(unsigned long)
+AC_CHECK_SIZEOF(size_t)
+AC_CHECK_SIZEOF(long long)
+AC_CHECK_SIZEOF(unsigned long long)
+AC_CHECK_SIZEOF(void *)
+AC_CHECK_SIZEOF(intptr_t)
+AC_CHECK_SIZEOF(uintptr_t)
+AC_CHECK_SIZEOF(ptrdiff_t)
+
+if test "$ac_cv_sizeof_long" -ne "$ac_cv_sizeof_void_p"; then
+ AC_MSG_ERROR(sizes of long and void* are not identical)
+fi
+
+if test "$ac_cv_sizeof_ptrdiff_t" -eq 0; then
+ SCM_I_GSC_T_PTRDIFF='"ptrdiff_t"'
+else
+ SCM_I_GSC_T_PTRDIFF='"long"'
+fi
+AC_SUBST([SCM_I_GSC_T_PTRDIFF])
+
+AC_CHECK_HEADERS([stdint.h])
+AC_CHECK_HEADERS([inttypes.h])
+
+SCM_I_GSC_NEEDS_STDINT_H=0
+SCM_I_GSC_NEEDS_INTTYPES_H=0
+
+### intptr and uintptr (try not to use inttypes if we don't have to)
+if test "$ac_cv_header_inttypes_h" = yes; then
+ if test "$ac_cv_sizeof_intptr_t" -eq 0; then
+ AC_CHECK_SIZEOF([intptr_t],,[#include <inttypes.h>
+#include <stdio.h>])
+ if test "$ac_cv_sizeof_intptr_t" -ne 0; then
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+ fi
+ fi
+ if test "$ac_cv_sizeof_uintptr_t" -eq 0; then
+ AC_CHECK_SIZEOF([uintptr_t],,[#include <inttypes.h>
+#include <stdio.h>])
+ if test "$ac_cv_sizeof_uintptr_t" -ne 0; then
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+ fi
+ fi
+fi
+
+### See what's provided by stdint.h
+if test "$ac_cv_header_stdint_h" = yes; then
+ AC_CHECK_TYPE([int8_t],[scm_stdint_has_int8=1],,[#include <stdint.h>])
+ AC_CHECK_TYPE([uint8_t],[scm_stdint_has_uint8=1],,[#include <stdint.h>])
+ AC_CHECK_TYPE([int16_t],[scm_stdint_has_int16=1],,[#include <stdint.h>])
+ AC_CHECK_TYPE([uint16_t],[scm_stdint_has_uint16=1],,[#include <stdint.h>])
+ AC_CHECK_TYPE([int32_t],[scm_stdint_has_int32=1],,[#include <stdint.h>])
+ AC_CHECK_TYPE([uint32_t],[scm_stdint_has_uint32=1],,[#include <stdint.h>])
+ AC_CHECK_TYPE([int64_t],[scm_stdint_has_int64=1],,[#include <stdint.h>])
+ AC_CHECK_TYPE([uint64_t],[scm_stdint_has_uint64=1],,[#include <stdint.h>])
+fi
+
+# so we don't get confused by the cache (wish there was a better way
+# to check particular headers for the same type...)
+
+unset ac_cv_type_int8_t
+unset ac_cv_type_uint8_t
+unset ac_cv_type_int16_t
+unset ac_cv_type_uint16_t
+unset ac_cv_type_int32_t
+unset ac_cv_type_uint32_t
+unset ac_cv_type_int64_t
+unset ac_cv_type_uint64_t
+
+### See what's provided by inttypes.h
+if test "$ac_cv_header_inttypes_h" = yes; then
+ AC_CHECK_TYPE([int8_t],[scm_inttypes_has_int8=1],,[#include <inttypes.h>])
+ AC_CHECK_TYPE([uint8_t],[scm_inttypes_has_uint8=1],,[#include <inttypes.h>])
+ AC_CHECK_TYPE([int16_t],[scm_inttypes_has_int16=1],,[#include <inttypes.h>])
+ AC_CHECK_TYPE([uint16_t],[scm_inttypes_has_uint16=1],,[#include <inttypes.h>])
+ AC_CHECK_TYPE([int32_t],[scm_inttypes_has_int32=1],,[#include <inttypes.h>])
+ AC_CHECK_TYPE([uint32_t],[scm_inttypes_has_uint32=1],,[#include <inttypes.h>])
+ AC_CHECK_TYPE([int64_t],[scm_inttypes_has_int64=1],,[#include <inttypes.h>])
+ AC_CHECK_TYPE([uint64_t],[scm_inttypes_has_uint64=1],,[#include <inttypes.h>])
+fi
+
+# Try hard to find definitions for some required scm_t_*int* types.
+
+### Required type scm_t_int8
+if test "$ac_cv_sizeof_char" -eq 1; then
+ SCM_I_GSC_T_INT8='"char"'
+elif test "$scm_stdint_has_int8"; then
+ SCM_I_GSC_T_INT8='"int8_t"'
+ SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_int8"; then
+ SCM_I_GSC_T_INT8='"int8_t"'
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+else
+ AC_MSG_ERROR([Can't find appropriate type for scm_t_int8.])
+fi
+AC_SUBST([SCM_I_GSC_T_INT8])
+
+### Required type scm_t_uint8
+if test "$ac_cv_sizeof_unsigned_char" -eq 1; then
+ SCM_I_GSC_T_UINT8='"unsigned char"'
+elif test "$scm_stdint_has_uint8"; then
+ SCM_I_GSC_T_UINT8='"uint8_t"'
+ SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_uint8"; then
+ SCM_I_GSC_T_UINT8='"uint8_t"'
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+else
+ AC_MSG_ERROR([Can't find appropriate type for scm_t_uint8.])
+fi
+AC_SUBST([SCM_I_GSC_T_UINT8])
+
+
+### Required type scm_t_int16 (ANSI C says int or short might work)
+if test "$ac_cv_sizeof_int" -eq 2; then
+ SCM_I_GSC_T_INT16='"int"'
+elif test "$ac_cv_sizeof_short" -eq 2; then
+ SCM_I_GSC_T_INT16='"short"'
+elif test "$scm_stdint_has_int16"; then
+ SCM_I_GSC_T_INT16='"int16_t"'
+ SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_int16"; then
+ SCM_I_GSC_T_INT16='"int16_t"'
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+else
+ AC_MSG_ERROR([Can't find appropriate type for scm_t_int16.])
+fi
+AC_SUBST([SCM_I_GSC_T_INT16])
+
+### Required type scm_t_uint16 (ANSI C says int or short might work)
+if test "$ac_cv_sizeof_unsigned_int" -eq 2; then
+ SCM_I_GSC_T_UINT16='"unsigned int"'
+elif test "$ac_cv_sizeof_unsigned_short" -eq 2; then
+ SCM_I_GSC_T_UINT16='"unsigned short"'
+elif test "$scm_stdint_has_uint16"; then
+ SCM_I_GSC_T_UINT16='"uint16_t"'
+ SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_uint16"; then
+ SCM_I_GSC_T_UINT16='"uint16_t"'
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+else
+ AC_MSG_ERROR([Can't find appropriate type for scm_t_uint16.])
+fi
+AC_SUBST([SCM_I_GSC_T_UINT16])
+
+
+### Required type scm_t_int32 (ANSI C says int, short, or long might work)
+if test "$ac_cv_sizeof_int" -eq 4; then
+ SCM_I_GSC_T_INT32='"int"'
+elif test "$ac_cv_sizeof_long" -eq 4; then
+ SCM_I_GSC_T_INT32='"long"'
+elif test "$ac_cv_sizeof_short" -eq 4; then
+ SCM_I_GSC_T_INT32='"short"'
+elif test "$scm_stdint_has_int32"; then
+ SCM_I_GSC_T_INT32='"int32_t"'
+ SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_int32"; then
+ SCM_I_GSC_T_INT32='"int32_t"'
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+else
+ AC_MSG_ERROR([Can't find appropriate type for scm_t_int32.])
+fi
+AC_SUBST([SCM_I_GSC_T_INT32])
+
+### Required type scm_t_uint32 (ANSI C says int, short, or long might work)
+if test "$ac_cv_sizeof_unsigned_int" -eq 4; then
+ SCM_I_GSC_T_UINT32='"unsigned int"'
+elif test "$ac_cv_sizeof_unsigned_long" -eq 4; then
+ SCM_I_GSC_T_UINT32='"unsigned long"'
+elif test "$ac_cv_sizeof_unsigned_short" -eq 4; then
+ SCM_I_GSC_T_UINT32='"unsigned short"'
+elif test "$scm_stdint_has_uint32"; then
+ SCM_I_GSC_T_UINT32='"uint32_t"'
+ SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_uint32"; then
+ SCM_I_GSC_T_UINT32='"uint32_t"'
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+else
+ AC_MSG_ERROR([Can't find appropriate type for scm_t_uint32.])
+fi
+AC_SUBST([SCM_I_GSC_T_UINT32])
+
+### Optional type scm_t_int64 (ANSI C says int, short, or long might work)
+### Also try long long if we have it.
+SCM_I_GSC_T_INT64=0
+if test "$ac_cv_sizeof_int" -eq 8; then
+ SCM_I_GSC_T_INT64='"int"'
+elif test "$ac_cv_sizeof_long" -eq 8; then
+ SCM_I_GSC_T_INT64='"long"'
+elif test "$ac_cv_sizeof_short" -eq 8; then
+ SCM_I_GSC_T_INT64='"short"'
+elif test "$ac_cv_sizeof_long_long" -eq 8; then
+ SCM_I_GSC_T_INT64='"long long"'
+elif test "$scm_stdint_has_int64"; then
+ SCM_I_GSC_T_INT64='"int64_t"'
+ SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_int64"; then
+ SCM_I_GSC_T_INT64='"int64_t"'
+ SCM_I_GSC_NEEDS_INTTYPES_H=1
+else
+ AC_MSG_ERROR([Can't find appropriate type for scm_t_int64.])