From 1c0b8a75b49ed9d7fcee2b247a6afb585cb19a75 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 18 May 2024 12:25:41 +0200 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ doc/glibc-headers/endian.texi | 8 ++++++-- tests/test-endian.c | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 217e0dd059..322aaf362d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-05-18 Bruno Haible + + 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 endian: Add tests. diff --git a/doc/glibc-headers/endian.texi b/doc/glibc-headers/endian.texi index 5c7cb72429..ebaeb4fe7f 100644 --- a/doc/glibc-headers/endian.texi +++ b/doc/glibc-headers/endian.texi @@ -1,7 +1,11 @@ @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}. @@ -11,7 +15,7 @@ Portability problems fixed by Gnulib: @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: diff --git a/tests/test-endian.c b/tests/test-endian.c index 919faa56f5..739b18964e 100644 --- a/tests/test-endian.c +++ b/tests/test-endian.c @@ -30,7 +30,17 @@ uint32_t t2; 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 -- 2.39.5