#define PRI16 ""
#define PRILEAST16 ""
#define PRIFAST16 ""
-#if _WORD_SIZE == 2
-#define PRI32 "l"
-#define PRILEAST32 "l"
-#define PRIFAST32 "l"
-#else
+
+#if __SIZEOF_LONG__ > 4
#define PRI32 ""
-#define PRILEAST32 ""
-#define PRIFAST32 ""
+#else
+#define PRI32 "l"
#endif
-#if _WORD_SIZE > 2 && __L64
+#define PRILEAST32 PRI32
+#define PRIFAST32 PRI32
+
+#if defined(__LONG_LONG_SUPPORTED)
+#define PRI64 "ll"
+#elif _WORD_SIZE > 2 && __L64
#define PRI64 "l"
-#define PRILEAST64 "l"
-#define PRIFAST64 "l"
+#endif
+
+#ifdef PRI64
+#define PRILEAST64 PRI64
+#define PRIFAST64 PRI64
+#define PRIMAX PRI64
+#else
+#define PRIMAX PRI32
+#endif
+
+#if _PTR_SIZE == _WORD_SIZE
+#define PRIPTR ""
+#elif _PTR_SIZE == 2*_WORD_SIZE
+#define PRIPTR "l"
#endif
/* Macros for fprintf, the ones defined by the standard. */
#define PRId32 PRI32"d"
#define PRIdLEAST32 PRILEAST32"d"
#define PRIdFAST32 PRIFAST32"d"
-#if _WORD_SIZE > 2 && __L64
+#ifdef PRI64
#define PRId64 PRI64"d"
#define PRIdLEAST64 PRILEAST64"d"
#define PRIdFAST64 PRIFAST64"d"
#endif
+#define PRIdMAX PRIMAX"d"
+#define PRIdPTR PRIPTR"d"
#define PRIi8 PRI8"i"
#define PRIiLEAST8 PRILEAST8"i"
#define PRIi32 PRI32"i"
#define PRIiLEAST32 PRILEAST32"i"
#define PRIiFAST32 PRIFAST32"i"
-#if _WORD_SIZE > 2 && __L64
+#ifdef PRI64
#define PRIi64 PRI64"i"
#define PRIiLEAST64 PRILEAST64"i"
#define PRIiFAST64 PRIFAST64"i"
#endif
+#define PRIiMAX PRIMAX"i"
+#define PRIiPTR PRIPTR"i"
#define PRIo8 PRI8"o"
#define PRIoLEAST8 PRILEAST8"o"
#define PRIo32 PRI32"o"
#define PRIoLEAST32 PRILEAST32"o"
#define PRIoFAST32 PRIFAST32"o"
-#if _WORD_SIZE > 2 && __L64
+#ifdef PRI64
#define PRIo64 PRI64"o"
#define PRIoLEAST64 PRILEAST64"o"
#define PRIoFAST64 PRIFAST64"o"
#endif
+#define PRIoMAX PRIMAX"o"
+#define PRIoPTR PRIPTR"o"
#define PRIu8 PRI8"u"
#define PRIuLEAST8 PRILEAST8"u"
#define PRIu32 PRI32"u"
#define PRIuLEAST32 PRILEAST32"u"
#define PRIuFAST32 PRIFAST32"u"
-#if _WORD_SIZE > 2 && __L64
+#ifdef PRI64
#define PRIu64 PRI64"u"
#define PRIuLEAST64 PRILEAST64"u"
#define PRIuFAST64 PRIFAST64"u"
#endif
+#define PRIuMAX PRIMAX"u"
+#define PRIuPTR PRIPTR"u"
#define PRIx8 PRI8"x"
#define PRIxLEAST8 PRILEAST8"x"
#define PRIx32 PRI32"x"
#define PRIxLEAST32 PRILEAST32"x"
#define PRIxFAST32 PRIFAST32"x"
-#if _WORD_SIZE > 2 && __L64
+#ifdef PRI64
#define PRIx64 PRI64"x"
#define PRIxLEAST64 PRILEAST64"x"
#define PRIxFAST64 PRIFAST64"x"
#endif
+#define PRIxMAX PRIMAX"x"
+#define PRIxPTR PRIPTR"x"
#define PRIX8 PRI8"X"
#define PRIXLEAST8 PRILEAST8"X"
#define PRIX32 PRI32"X"
#define PRIXLEAST32 PRILEAST32"X"
#define PRIXFAST32 PRIFAST32"X"
-#if _WORD_SIZE > 2 && __L64
+#ifdef PRI64
#define PRIX64 PRI64"X"
#define PRIXLEAST64 PRILEAST64"X"
#define PRIXFAST64 PRIFAST64"X"
#endif
+#define PRIXMAX PRIMAX"X"
+#define PRIXPTR PRIPTR"X"
/* Macros to scan integers with fscanf(), nonstandard first group. */
#define SCN8 "hh"
#endif /* !__cplusplus || __STDC_FORMAT_MACROS */
/* Integer conversion functions for [u]intmax_t. */
+#ifdef __LONG_LONG_SUPPORTED
+#define stroimax(nptr, endptr, base) strtoll(nptr, endptr, base)
+#define stroumax(nptr, endptr, base) strtoull(nptr, endptr, base)
+#else
#define stroimax(nptr, endptr, base) strtol(nptr, endptr, base)
#define stroumax(nptr, endptr, base) strtoul(nptr, endptr, base)
+#endif
#endif /* _INTTYPES_H */
--- /dev/null
+#include <assert.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#if defined(__LONG_LONG_SUPPORTED) || (_WORD_SIZE > 2 && __L64)
+#define TEST_64_BIT
+#endif
+
+#define ERR err(__LINE__)
+
+#define MAX_ERROR 4
+static int errct;
+
+static void quit(void)
+{
+ if (errct == 0)
+ {
+ printf("ok\n");
+ exit(0);
+ }
+ else
+ {
+ printf("%d errors\n", errct);
+ exit(1);
+ }
+}
+
+static void err(int line)
+{
+ printf("error at line %d\n", line);
+ if (++errct >= MAX_ERROR)
+ quit();
+}
+
+#define TEST_PRINTF(type, macro, value, result) \
+{ \
+ char buffer[256]; \
+ snprintf(buffer, sizeof(buffer), "%" macro, (type) value); \
+ if (strcmp(buffer, result) != 0) err(__LINE__); \
+}
+
+int main(void)
+{
+#ifdef __LONG_LONG_SUPPORTED
+ printf("Test 49 (GCC) ");
+#else
+ printf("Test 49 (ACK) ");
+#endif
+ fflush(stdout);
+
+ /* test integer sizes */
+ if (sizeof(int8_t) != 1) ERR;
+ if (sizeof(uint8_t) != 1) ERR;
+ if (sizeof(int_fast8_t) < 1) ERR;
+ if (sizeof(uint_fast8_t) < 1) ERR;
+ if (sizeof(int_least8_t) < 1) ERR;
+ if (sizeof(uint_least8_t) < 1) ERR;
+ if (sizeof(int16_t) != 2) ERR;
+ if (sizeof(uint16_t) != 2) ERR;
+ if (sizeof(int_fast16_t) < 2) ERR;
+ if (sizeof(uint_fast16_t) < 2) ERR;
+ if (sizeof(int_least16_t) < 2) ERR;
+ if (sizeof(uint_least16_t) < 2) ERR;
+ if (sizeof(int32_t) != 4) ERR;
+ if (sizeof(uint32_t) != 4) ERR;
+ if (sizeof(int_fast32_t) < 4) ERR;
+ if (sizeof(uint_fast32_t) < 4) ERR;
+ if (sizeof(int_least32_t) < 4) ERR;
+ if (sizeof(uint_least32_t) < 4) ERR;
+#ifdef TEST_64_BIT
+ if (sizeof(int64_t) != 8) ERR;
+ if (sizeof(uint64_t) != 8) ERR;
+ if (sizeof(int_fast64_t) < 8) ERR;
+ if (sizeof(uint_fast64_t) < 8) ERR;
+ if (sizeof(int_least64_t) < 8) ERR;
+ if (sizeof(uint_least64_t) < 8) ERR;
+#endif
+ if (sizeof(intptr_t) != sizeof(void *)) ERR;
+ if (sizeof(uintptr_t) != sizeof(void *)) ERR;
+#ifdef TEST_64_BIT
+ if (sizeof(intmax_t) < 8) ERR;
+ if (sizeof(uintmax_t) < 8) ERR;
+#else
+ if (sizeof(intmax_t) < 4) ERR;
+ if (sizeof(uintmax_t) < 4) ERR;
+#endif
+
+ /* test integer signedness */
+ if ((int8_t) (-1) >= 0) ERR;
+ if ((uint8_t) (-1) <= 0) ERR;
+ if ((int_fast8_t) (-1) >= 0) ERR;
+ if ((uint_fast8_t) (-1) <= 0) ERR;
+ if ((int_least8_t) (-1) >= 0) ERR;
+ if ((uint_least8_t) (-1) <= 0) ERR;
+ if ((int16_t) (-1) >= 0) ERR;
+ if ((uint16_t) (-1) <= 0) ERR;
+ if ((int_fast16_t) (-1) >= 0) ERR;
+ if ((uint_fast16_t) (-1) <= 0) ERR;
+ if ((int_least16_t) (-1) >= 0) ERR;
+ if ((uint_least16_t) (-1) <= 0) ERR;
+ if ((int32_t) (-1) >= 0) ERR;
+ if ((uint32_t) (-1) <= 0) ERR;
+ if ((int_fast32_t) (-1) >= 0) ERR;
+ if ((uint_fast32_t) (-1) <= 0) ERR;
+ if ((int_least32_t) (-1) >= 0) ERR;
+ if ((uint_least32_t) (-1) <= 0) ERR;
+#ifdef TEST_64_BIT
+ if ((int64_t) (-1) >= 0) ERR;
+ if ((uint64_t) (-1) <= 0) ERR;
+ if ((int_fast64_t) (-1) >= 0) ERR;
+ if ((uint_fast64_t) (-1) <= 0) ERR;
+ if ((int_least64_t) (-1) >= 0) ERR;
+ if ((uint_least64_t) (-1) <= 0) ERR;
+#endif
+ if ((intptr_t) (-1) >= 0) ERR;
+ if ((uintptr_t) (-1) <= 0) ERR;
+ if ((intptr_t) (-1) >= 0) ERR;
+ if ((uintptr_t) (-1) <= 0) ERR;
+
+ /* test printf */
+ TEST_PRINTF(int32_t, PRId32, INT32_MIN, "-2147483648");
+ TEST_PRINTF(int32_t, PRId32, INT32_MAX, "2147483647");
+ TEST_PRINTF(int32_t, PRIi32, INT32_MIN, "-2147483648");
+ TEST_PRINTF(int32_t, PRIi32, INT32_MAX, "2147483647");
+ TEST_PRINTF(uint32_t, PRIu32, UINT32_MAX, "4294967295");
+ TEST_PRINTF(uint32_t, PRIX32, UINT32_MAX, "FFFFFFFF");
+ TEST_PRINTF(uint32_t, PRIx32, UINT32_MAX, "ffffffff");
+ TEST_PRINTF(uint32_t, PRIo32, UINT32_MAX, "37777777777");
+
+ TEST_PRINTF(int_fast32_t, PRIdFAST32, INT32_MIN, "-2147483648");
+ TEST_PRINTF(int_fast32_t, PRIdFAST32, INT32_MAX, "2147483647");
+ TEST_PRINTF(int_fast32_t, PRIiFAST32, INT32_MIN, "-2147483648");
+ TEST_PRINTF(int_fast32_t, PRIiFAST32, INT32_MAX, "2147483647");
+ TEST_PRINTF(uint_fast32_t, PRIuFAST32, UINT32_MAX, "4294967295");
+ TEST_PRINTF(uint_fast32_t, PRIXFAST32, UINT32_MAX, "FFFFFFFF");
+ TEST_PRINTF(uint_fast32_t, PRIxFAST32, UINT32_MAX, "ffffffff");
+ TEST_PRINTF(uint_fast32_t, PRIoFAST32, UINT32_MAX, "37777777777");
+
+ TEST_PRINTF(int_least32_t, PRIdLEAST32, INT32_MIN, "-2147483648");
+ TEST_PRINTF(int_least32_t, PRIdLEAST32, INT32_MAX, "2147483647");
+ TEST_PRINTF(int_least32_t, PRIiLEAST32, INT32_MIN, "-2147483648");
+ TEST_PRINTF(int_least32_t, PRIiLEAST32, INT32_MAX, "2147483647");
+ TEST_PRINTF(uint_least32_t, PRIuLEAST32, UINT32_MAX, "4294967295");
+ TEST_PRINTF(uint_least32_t, PRIXLEAST32, UINT32_MAX, "FFFFFFFF");
+ TEST_PRINTF(uint_least32_t, PRIxLEAST32, UINT32_MAX, "ffffffff");
+ TEST_PRINTF(uint_least32_t, PRIoLEAST32, UINT32_MAX, "37777777777");
+
+#ifdef TEST_64_BIT
+ TEST_PRINTF(int64_t, PRId64, INT64_MIN, "-9223372036854775808");
+ TEST_PRINTF(int64_t, PRId64, INT64_MAX, "9223372036854775807");
+ TEST_PRINTF(int64_t, PRIi64, INT64_MIN, "-9223372036854775808");
+ TEST_PRINTF(int64_t, PRIi64, INT64_MAX, "9223372036854775807");
+ TEST_PRINTF(uint64_t, PRIu64, UINT64_MAX, "18446744073709551615");
+ TEST_PRINTF(uint64_t, PRIX64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
+ TEST_PRINTF(uint64_t, PRIx64, UINT64_MAX, "ffffffffffffffff");
+ TEST_PRINTF(uint64_t, PRIo64, UINT64_MAX, "1777777777777777777777");
+
+ TEST_PRINTF(int_fast64_t, PRIdFAST64, INT64_MIN, "-9223372036854775808");
+ TEST_PRINTF(int_fast64_t, PRIdFAST64, INT64_MAX, "9223372036854775807");
+ TEST_PRINTF(int_fast64_t, PRIiFAST64, INT64_MIN, "-9223372036854775808");
+ TEST_PRINTF(int_fast64_t, PRIiFAST64, INT64_MAX, "9223372036854775807");
+ TEST_PRINTF(uint_fast64_t, PRIuFAST64, UINT64_MAX, "18446744073709551615");
+ TEST_PRINTF(uint_fast64_t, PRIXFAST64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
+ TEST_PRINTF(uint_fast64_t, PRIxFAST64, UINT64_MAX, "ffffffffffffffff");
+ TEST_PRINTF(uint_fast64_t, PRIoFAST64, UINT64_MAX, "1777777777777777777777");
+
+ TEST_PRINTF(int_least64_t, PRIdLEAST64, INT64_MIN, "-9223372036854775808");
+ TEST_PRINTF(int_least64_t, PRIdLEAST64, INT64_MAX, "9223372036854775807");
+ TEST_PRINTF(int_least64_t, PRIiLEAST64, INT64_MIN, "-9223372036854775808");
+ TEST_PRINTF(int_least64_t, PRIiLEAST64, INT64_MAX, "9223372036854775807");
+ TEST_PRINTF(uint_least64_t, PRIuLEAST64, UINT64_MAX, "18446744073709551615");
+ TEST_PRINTF(uint_least64_t, PRIXLEAST64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
+ TEST_PRINTF(uint_least64_t, PRIxLEAST64, UINT64_MAX, "ffffffffffffffff");
+ TEST_PRINTF(uint_least64_t, PRIoLEAST64, UINT64_MAX, "1777777777777777777777");
+
+ TEST_PRINTF(intmax_t, PRIdMAX, INT64_MIN, "-9223372036854775808");
+ TEST_PRINTF(intmax_t, PRIdMAX, INT64_MAX, "9223372036854775807");
+ TEST_PRINTF(intmax_t, PRIiMAX, INT64_MIN, "-9223372036854775808");
+ TEST_PRINTF(intmax_t, PRIiMAX, INT64_MAX, "9223372036854775807");
+ TEST_PRINTF(uintmax_t, PRIuMAX, UINT64_MAX, "18446744073709551615");
+ TEST_PRINTF(uintmax_t, PRIXMAX, UINT64_MAX, "FFFFFFFFFFFFFFFF");
+ TEST_PRINTF(uintmax_t, PRIxMAX, UINT64_MAX, "ffffffffffffffff");
+ TEST_PRINTF(uintmax_t, PRIoMAX, UINT64_MAX, "1777777777777777777777");
+#else
+ TEST_PRINTF(intmax_t, PRIdMAX, INT32_MIN, "-2147483648");
+ TEST_PRINTF(intmax_t, PRIdMAX, INT32_MAX, "2147483647");
+ TEST_PRINTF(intmax_t, PRIiMAX, INT32_MIN, "-2147483648");
+ TEST_PRINTF(intmax_t, PRIiMAX, INT32_MAX, "2147483647");
+ TEST_PRINTF(uintmax_t, PRIuMAX, UINT32_MAX, "4294967295");
+ TEST_PRINTF(uintmax_t, PRIXMAX, UINT32_MAX, "FFFFFFFF");
+ TEST_PRINTF(uintmax_t, PRIxMAX, UINT32_MAX, "ffffffff");
+ TEST_PRINTF(uintmax_t, PRIoMAX, UINT32_MAX, "37777777777");
+#endif
+
+ TEST_PRINTF(intptr_t, PRIdPTR, INT32_MIN, "-2147483648");
+ TEST_PRINTF(intptr_t, PRIdPTR, INT32_MAX, "2147483647");
+ TEST_PRINTF(intptr_t, PRIiPTR, INT32_MIN, "-2147483648");
+ TEST_PRINTF(intptr_t, PRIiPTR, INT32_MAX, "2147483647");
+ TEST_PRINTF(uintptr_t, PRIuPTR, UINT32_MAX, "4294967295");
+ TEST_PRINTF(uintptr_t, PRIXPTR, UINT32_MAX, "FFFFFFFF");
+ TEST_PRINTF(uintptr_t, PRIxPTR, UINT32_MAX, "ffffffff");
+ TEST_PRINTF(uintptr_t, PRIoPTR, UINT32_MAX, "37777777777");
+
+ /* done */
+ quit();
+ assert(0);
+ return -1;
+}