8 #if __GNUC_PREREQ (6, 0)
9 /* GCC 6.0 warns on big endian systems about:
10 htobeXX (beXXtoh (i)) != i
11 warning: self-comparison always evaluates to false [-Wtautological-compare]
12 because htobeXX(x) and beXXtoh(x) is defined to (x)
13 in string/endian.h on big endian systems.
14 The same applies to htoleXX/leXXtoh on little endian systems. */
15 # define DIAG_IGNORE_NEEDS_COMMENT_TAUTOLOGICAL_COMPARE() \
16 DIAG_IGNORE_NEEDS_COMMENT (6, "-Wtautological-compare")
18 # define DIAG_IGNORE_NEEDS_COMMENT_TAUTOLOGICAL_COMPARE()
26 for (uint64_t i = 0; i < (~UINT64_C (0)) >> 2; i = (i << 1) + 3)
28 if (i < UINT64_C (65536))
30 DIAG_PUSH_NEEDS_COMMENT;
31 DIAG_IGNORE_NEEDS_COMMENT_TAUTOLOGICAL_COMPARE ();
32 if (htobe16 (be16toh (i)) != i)
34 printf ("htobe16 (be16toh (%" PRIx64 ")) == %" PRIx16 "\n",
35 i, (uint16_t) htobe16 (be16toh (i)));
38 if (htole16 (le16toh (i)) != i)
40 printf ("htole16 (le16toh (%" PRIx64 ")) == %" PRIx16 "\n",
41 i, (uint16_t) htole16 (le16toh (i)));
44 DIAG_POP_NEEDS_COMMENT;
47 n[__BYTE_ORDER == __LITTLE_ENDIAN] = bswap_16 (i);
48 n[__BYTE_ORDER == __BIG_ENDIAN] = i;
49 if (htole16 (i) != n[0])
51 printf ("htole16 (%" PRIx64 ") == %" PRIx16 " != %" PRIx16 "\n",
52 i, (uint16_t) htole16 (i), n[0]);
55 if (htobe16 (i) != n[1])
57 printf ("htobe16 (%" PRIx64 ") == %" PRIx16 " != %" PRIx16 "\n",
58 i, (uint16_t) htobe16 (i), n[1]);
63 if (i < UINT64_C (4294967296))
65 DIAG_PUSH_NEEDS_COMMENT;
66 DIAG_IGNORE_NEEDS_COMMENT_TAUTOLOGICAL_COMPARE ();
67 if (htobe32 (be32toh (i)) != i)
69 printf ("htobe32 (be32toh (%" PRIx64 ")) == %" PRIx32 "\n",
70 i, (uint32_t) htobe32 (be32toh (i)));
73 if (htole32 (le32toh (i)) != i)
75 printf ("htole32 (le32toh (%" PRIx64 ")) == %" PRIx32 "\n",
76 i, (uint32_t) htole32 (le32toh (i)));
79 DIAG_POP_NEEDS_COMMENT;
82 n[__BYTE_ORDER == __LITTLE_ENDIAN] = bswap_32 (i);
83 n[__BYTE_ORDER == __BIG_ENDIAN] = i;
84 if (htole32 (i) != n[0])
86 printf ("htole32 (%" PRIx64 ") == %" PRIx32 " != %" PRIx32 "\n",
87 i, (uint32_t) htole32 (i), n[0]);
90 if (htobe32 (i) != n[1])
92 printf ("htobe32 (%" PRIx64 ") == %" PRIx32 " != %" PRIx32 "\n",
93 i, (uint32_t) htobe32 (i), n[1]);
98 DIAG_PUSH_NEEDS_COMMENT;
99 DIAG_IGNORE_NEEDS_COMMENT_TAUTOLOGICAL_COMPARE ();
100 if (htobe64 (be64toh (i)) != i)
102 printf ("htobe64 (be64toh (%" PRIx64 ")) == %" PRIx64 "\n",
103 i, htobe64 (be64toh (i)));
106 if (htole64 (le64toh (i)) != i)
108 printf ("htole64 (le64toh (%" PRIx64 ")) == %" PRIx64 "\n",
109 i, htole64 (le64toh (i)));
112 DIAG_POP_NEEDS_COMMENT;
115 n[__BYTE_ORDER == __LITTLE_ENDIAN] = bswap_64 (i);
116 n[__BYTE_ORDER == __BIG_ENDIAN] = i;
117 if (htole64 (i) != n[0])
119 printf ("htole64 (%" PRIx64 ") == %" PRIx64 " != %" PRIx64 "\n",
120 i, htole64 (i), n[0]);
123 if (htobe64 (i) != n[1])
125 printf ("htobe64 (%" PRIx64 ") == %" PRIx64 " != %" PRIx64 "\n",
126 i, htobe64 (i), n[1]);
134 #include <support/test-driver.c>