* doc/headers/assert.texi (assert.h): Document assert module use.
[gnulib.git] / lib / stdint_.h
index b2a53da..4fa5251 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2002, 2004-2006 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc.
    Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
    This file is part of gnulib.
 
    for the "fast" types and macros, which we recommend against using
    in public interfaces due to compiler differences.  */
 
-/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
-   IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).  */
-#if @HAVE_SYS_TYPES_H@
-# include <sys/types.h>
-#endif
-
-/* Get LONG_MIN, LONG_MAX, ULONG_MAX.  */
-#include <limits.h>
-
 #if @HAVE_STDINT_H@
 # if defined __sgi && ! defined __c99
    /* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users
      Include it before <inttypes.h>, since any "#include <stdint.h>"
      in <inttypes.h> would reinclude us, skipping our contents because
      _GL_STDINT_H is defined.  */
-# include @FULL_PATH_STDINT_H@
+# include @ABSOLUTE_STDINT_H@
 #endif
 
+/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
+   IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
+   AIX 5.2 <sys/types.h> isn't needed and causes troubles.
+   MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
+   relies on the system <stdint.h> definitions, so include
+   <sys/types.h> after @ABSOLUTE_STDINT_H@.  */
+#if @HAVE_SYS_TYPES_H@ && ! defined _AIX
+# include <sys/types.h>
+#endif
+
+/* Get LONG_MIN, LONG_MAX, ULONG_MAX.  */
+#include <limits.h>
+
 #if @HAVE_INTTYPES_H@
   /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
      int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
      <inttypes.h> also defines intptr_t and uintptr_t.  */
+# define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
 # include <inttypes.h>
+# undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
+#elif @HAVE_SYS_INTTYPES_H@
+  /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
+     the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX.  */
+# include <sys/inttypes.h>
 #endif
 
 #if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
 # include <sys/bitypes.h>
 #endif
 
-#if @HAVE_SYS_INTTYPES_H@ && !@HAVE_INTTYPES_H@
-  /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
-     the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX.
-     But note that <sys/int_types.h> contains only the type definitions!  */
-# include <sys/inttypes.h>
-#endif
-
 #if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
 
 /* Get WCHAR_MIN, WCHAR_MAX.  */
-# if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX)
-   /* BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
-      <wchar.h>.  */
-#  include <stdio.h>
-#  include <time.h>
+# if ! (defined WCHAR_MIN && defined WCHAR_MAX)
 #  include <wchar.h>
 # endif
 
 #define int32_t int
 #define uint32_t unsigned int
 
-#undef int64_t
-#undef uint64_t
+/* Do not undefine int64_t if gnulib is not being used with 64-bit
+   types, since otherwise it breaks platforms like Tandem/NSK.  */
 #if LONG_MAX >> 31 >> 31 == 1
+# undef int64_t
 # define int64_t long int
-# define uint64_t unsigned long int
+# define GL_INT64_T
 #elif defined _MSC_VER
+# undef int64_t
 # define int64_t __int64
-# define uint64_t unsigned __int64
+# define GL_INT64_T
 #elif @HAVE_LONG_LONG_INT@
+# undef int64_t
 # define int64_t long long int
+# define GL_INT64_T
+#endif
+
+#if ULONG_MAX >> 31 >> 31 >> 1 == 1
+# undef uint64_t
+# define uint64_t unsigned long int
+# define GL_UINT64_T
+#elif defined _MSC_VER
+# undef uint64_t
+# define uint64_t unsigned __int64
+# define GL_UINT64_T
+#elif @HAVE_UNSIGNED_LONG_LONG_INT@
+# undef uint64_t
 # define uint64_t unsigned long long int
+# define GL_UINT64_T
 #endif
 
 /* Avoid collision with Solaris 2.5.1 <pthread.h> etc.  */
 #define uint_least16_t uint16_t
 #define int_least32_t int32_t
 #define uint_least32_t uint32_t
-#ifdef int64_t
+#ifdef GL_INT64_T
 # define int_least64_t int64_t
+#endif
+#ifdef GL_UINT64_T
 # define uint_least64_t uint64_t
 #endif
 
 #define uint_fast16_t unsigned int_fast16_t
 #define int_fast32_t long int
 #define uint_fast32_t unsigned int_fast32_t
-#ifdef int64_t
+#ifdef GL_INT64_T
 # define int_fast64_t int64_t
+#endif
+#ifdef GL_UINT64_T
 # define uint_fast64_t uint64_t
 #endif
 
    public header files. */
 
 #undef intmax_t
-#undef uintmax_t
 #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
 # define intmax_t long long int
-# define uintmax_t unsigned long long int
-#elif defined int64_t
+#elif defined GL_INT64_T
 # define intmax_t int64_t
-# define uintmax_t uint64_t
 #else
 # define intmax_t long int
+#endif
+
+#undef uintmax_t
+#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
+# define uintmax_t unsigned long long int
+#elif defined GL_UINT64_T
+# define uintmax_t uint64_t
+#else
 # define uintmax_t unsigned long int
 #endif
 
 
 #undef INT64_MIN
 #undef INT64_MAX
-#undef UINT64_MAX
-#ifdef int64_t
-# define INT64_MIN  (~ INT64_MAX)
+#ifdef GL_INT64_T
+/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
+   evaluates the latter incorrectly in preprocessor expressions.  */
+# define INT64_MIN  (- INTMAX_C (1) << 63)
 # define INT64_MAX  INTMAX_C (9223372036854775807)
+#endif
+
+#undef UINT64_MAX
+#ifdef GL_UINT64_T
 # define UINT64_MAX  UINTMAX_C (18446744073709551615)
 #endif
 
 
 #undef INT_LEAST64_MIN
 #undef INT_LEAST64_MAX
-#undef UINT_LEAST64_MAX
-#ifdef int64_t
+#ifdef GL_INT64_T
 # define INT_LEAST64_MIN  INT64_MIN
 # define INT_LEAST64_MAX  INT64_MAX
+#endif
+
+#undef UINT_LEAST64_MAX
+#ifdef GL_UINT64_T
 # define UINT_LEAST64_MAX  UINT64_MAX
 #endif
 
 
 #undef INT_FAST64_MIN
 #undef INT_FAST64_MAX
-#undef UINT_FAST64_MAX
-#ifdef int64_t
+#ifdef GL_INT64_T
 # define INT_FAST64_MIN  INT64_MIN
 # define INT_FAST64_MAX  INT64_MAX
+#endif
+
+#undef UINT_FAST64_MAX
+#ifdef GL_UINT64_T
 # define UINT_FAST64_MAX  UINT64_MAX
 #endif
 
 
 #undef INTMAX_MIN
 #undef INTMAX_MAX
-#undef UINTMAX_MAX
-#define INTMAX_MIN  (~ INTMAX_MAX)
 #ifdef INT64_MAX
+# define INTMAX_MIN  INT64_MIN
 # define INTMAX_MAX  INT64_MAX
-# define UINTMAX_MAX  UINT64_MAX
 #else
+# define INTMAX_MIN  INT32_MIN
 # define INTMAX_MAX  INT32_MAX
+#endif
+
+#undef UINTMAX_MAX
+#ifdef UINT64_MAX
+# define UINTMAX_MAX  UINT64_MAX
+#else
 # define UINTMAX_MAX  UINT32_MAX
 #endif
 
 #define WINT_MAX  \
    _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
 
+#endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */
+
 /* 7.18.4. Macros for integer constants */
 
+#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
+
 /* 7.18.4.1. Macros for minimum-width integer constants */
 /* According to ISO C 99 Technical Corrigendum 1 */
 
 #undef UINT64_C
 #if LONG_MAX >> 31 >> 31 == 1
 # define INT64_C(x) x##L
-# define UINT64_C(x) x##UL
 #elif defined _MSC_VER
 # define INT64_C(x) x##i64
-# define UINT64_C(x) x##ui64
 #elif @HAVE_LONG_LONG_INT@
 # define INT64_C(x) x##LL
+#endif
+#if ULONG_MAX >> 31 >> 31 >> 1 == 1
+# define UINT64_C(x) x##UL
+#elif defined _MSC_VER
+# define UINT64_C(x) x##ui64
+#elif @HAVE_UNSIGNED_LONG_LONG_INT@
 # define UINT64_C(x) x##ULL
 #endif
 
 /* 7.18.4.2. Macros for greatest-width integer constants */
 
 #undef INTMAX_C
-#undef UINTMAX_C
 #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
 # define INTMAX_C(x)   x##LL
-# define UINTMAX_C(x)  x##ULL
-#elif defined int64_t
+#elif defined GL_INT64_T
 # define INTMAX_C(x)   INT64_C(x)
-# define UINTMAX_C(x)  UINT64_C(x)
 #else
 # define INTMAX_C(x)   x##L
+#endif
+
+#undef UINTMAX_C
+#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
+# define UINTMAX_C(x)  x##ULL
+#elif defined GL_UINT64_T
+# define UINTMAX_C(x)  UINT64_C(x)
+#else
 # define UINTMAX_C(x)  x##UL
 #endif