+2024-05-18 Bruno Haible <bruno@clisp.org>
+
+ endian: Update doc and strengthen tests.
+ * doc/glibc-headers/endian.texi: Reference LSB and future POSIX
+ specifications. Update platforms list.
+ * tests/test-endian.c: Verify that BYTE_ORDER, LITTLE_ENDIAN, BIG_ENDIAN
+ can be used in #if.
+
2024-05-18 Collin Funk <collin.funk1@gmail.com>
endian: Add tests.
@node endian.h
@section @file{endian.h}
-Describe's the platform's endianness (byte ordering of words stored in memory).
+LSB specification:@* @url{https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/libc-ddefs.html}
+
+Future POSIX specification:@* @url{https://www.austingroupbugs.net/view.php?id=162}
+
+Describes the platform's endianness (byte ordering of words stored in memory).
Defines the macros @code{BYTE_ORDER}, @code{LITTLE_ENDIAN}, @code{BIG_ENDIAN},
@code{PDP_ENDIAN}.
@itemize
@item
This header file is missing on some platforms:
-macOS 11.1, FreeBSD 13.0, NetBSD 7.1, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 11.4, mingw, MSVC 14.
+macOS 11.1, FreeBSD 13.0, NetBSD 7.1, OpenBSD 3.8, Minix 3.1.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, mingw, MSVC 14.
@end itemize
Portability problems not fixed by Gnulib:
uint64_t t3;
#endif
+/* "These macros shall be suitable for use in #if preprocessing directives." */
+#if BYTE_ORDER == LITTLE_ENDIAN
+int a = 17;
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+int a = 19;
+#endif
+
+/* "The macros BIG_ENDIAN and LITTLE_ENDIAN shall have distinct values." */
static_assert (LITTLE_ENDIAN != BIG_ENDIAN);
+
static_assert (BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == BIG_ENDIAN);
#include <stdint.h>