Hi Collin,

> I've pushed the two patches adding a module to substitute endian.h.
> Pretty much the same as last time except using inline functions
> instead of macros and making sure variables are used in the m4 file.

Thanks!

> I've only mentioned the module in the documentation. It might make
> sense to put it in posix-headers/* once the next POSIX revision is
> actually released. Since now it is just a draft and is subject to
> change.

Yes. For now, it's sufficient to point talk about "Future POSIX specification".

> Also, the next POSIX revision seems like it is going to require
> int64_t and uint64_t support [2].

Yes; see also https://www.austingroupbugs.net/view.php?id=1799&nbn=2 .

> I've left the 64-bit functions
> #ifdef'd out though. I figured that was better since the module can be
> used as a dependency or in programs who still support old systems
> (assuming the 64-bit versions don't get used of course). I'm not sure
> if it is worth splitting things into separate modules just for that
> though.

I agree, separate modules would be overkill here.

> Also I ran the test cases on GCC, Clang, and Oracle CC, all x86-64. I
> don't have access to any other architectures. Someone running them on
> a big endian system would be very much appreciated, to catch any typos
> I may have made there. :)

Good point. I'm testing it on glibc/powerpc64 (in a VM) and AIX/powerpc64
(in the GCC compilefarm).

In the doc, the platforms list is less up-to-date than what our current
database has. See:

$ cd maint-tools/platforms/various-includes
$ ./show-portability --doc endian.h
macOS 11.1, FreeBSD 13.0, NetBSD 7.1, OpenBSD 3.8, Minix 3.3.0, AIX 7.3.1, 
HP-UX 11.31, IRIX 6.5, Solaris 11.4, mingw, MSVC 14.

Also, let me add a test for "These macros shall be suitable for use in #if
preprocessing directives." And a C++ test.


2024-05-18  Bruno Haible  <br...@clisp.org>

        endian tests: Verify that it can be used from C++.
        * tests/test-endian-c++.cc: New file.
        * modules/endian-c++-tests: New file.
        * modules/endian-tests (Depends-on): Add endian-c++-tests.

2024-05-18  Bruno Haible  <br...@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.

>From 1c0b8a75b49ed9d7fcee2b247a6afb585cb19a75 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 18 May 2024 12:25:41 +0200
Subject: [PATCH 1/2] 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  <br...@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.fu...@gmail.com>
 
 	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 @@
 @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 <stdint.h>
-- 
2.34.1

>From 59a670d792d16c5083b8657b972f1c00ce9905d1 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 18 May 2024 12:31:15 +0200
Subject: [PATCH 2/2] endian tests: Verify that it can be used from C++.

* tests/test-endian-c++.cc: New file.
* modules/endian-c++-tests: New file.
* modules/endian-tests (Depends-on): Add endian-c++-tests.
---
 ChangeLog                |  7 +++++++
 modules/endian-c++-tests | 17 +++++++++++++++++
 modules/endian-tests     |  1 +
 tests/test-endian-c++.cc | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+)
 create mode 100644 modules/endian-c++-tests
 create mode 100644 tests/test-endian-c++.cc

diff --git a/ChangeLog b/ChangeLog
index 322aaf362d..29adf56ab7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-05-18  Bruno Haible  <br...@clisp.org>
+
+	endian tests: Verify that it can be used from C++.
+	* tests/test-endian-c++.cc: New file.
+	* modules/endian-c++-tests: New file.
+	* modules/endian-tests (Depends-on): Add endian-c++-tests.
+
 2024-05-18  Bruno Haible  <br...@clisp.org>
 
 	endian: Update doc and strengthen tests.
diff --git a/modules/endian-c++-tests b/modules/endian-c++-tests
new file mode 100644
index 0000000000..d358ac122a
--- /dev/null
+++ b/modules/endian-c++-tests
@@ -0,0 +1,17 @@
+Files:
+tests/test-endian-c++.cc
+
+Status:
+c++-test
+
+Depends-on:
+ansi-c++-opt
+
+configure.ac:
+
+Makefile.am:
+if ANSICXX
+TESTS += test-endian-c++
+check_PROGRAMS += test-endian-c++
+test_endian_c___SOURCES = test-endian-c++.cc
+endif
diff --git a/modules/endian-tests b/modules/endian-tests
index 8ec67a1c42..e5d6da19b6 100644
--- a/modules/endian-tests
+++ b/modules/endian-tests
@@ -5,6 +5,7 @@ tests/macros.h
 Depends-on:
 assert-h
 stdint
+endian-c++-tests
 
 configure.ac:
 
diff --git a/tests/test-endian-c++.cc b/tests/test-endian-c++.cc
new file mode 100644
index 0000000000..25c1ab0834
--- /dev/null
+++ b/tests/test-endian-c++.cc
@@ -0,0 +1,32 @@
+/* Test of <endian.h> substitute in C++ mode.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <br...@clisp.org>, 2024.  */
+
+#define GNULIB_NAMESPACE gnulib
+#include <config.h>
+
+#include <endian.h>
+
+/* Check against conflicts between <endian.h> and the C++ header files.  */
+#include <stddef.h>
+#include <iostream>
+
+
+int
+main ()
+{
+}
-- 
2.34.1

Reply via email to