]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
idx: cleaner namespace on GNU
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 27 Apr 2026 20:05:32 +0000 (13:05 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 27 Apr 2026 20:17:24 +0000 (13:17 -0700)
* lib/idx.h: Include <stddef.h>, <stdint.h> only if needed.
(idx_t, IDX_MAX): Rely on builtin macros __PTRDIFF_TYPE__,
__PTRDIFF_MAX__ if present; this avoids polluting the namespace on
GNUish systems.

ChangeLog
lib/idx.h

index 72b45b1eb4b1a79afad753a1a2f4406e1cc1ac02..a3a87e555e6816aedbba975731e1548449b175f2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-04-27  Paul Eggert  <eggert@cs.ucla.edu>
+
+       idx: cleaner namespace on GNU
+       * lib/idx.h: Include <stddef.h>, <stdint.h> only if needed.
+       (idx_t, IDX_MAX): Rely on builtin macros __PTRDIFF_TYPE__,
+       __PTRDIFF_MAX__ if present; this avoids polluting the namespace on
+       GNUish systems.
+
 2026-04-26  Paul Eggert  <eggert@cs.ucla.edu>
 
        localename-unsafe: respect --disable-threads
index deb7dc4cb132b895c7956834371c939e1e049a65..d4f85323da52ab8862c6dac860e86c0f54fbebe0 100644 (file)
--- a/lib/idx.h
+++ b/lib/idx.h
 #ifndef _IDX_H
 #define _IDX_H
 
-/* Get ptrdiff_t.  */
-#include <stddef.h>
+#ifndef __PTRDIFF_TYPE__
+# include <stddef.h>
+#endif
 
-/* Get PTRDIFF_MAX.  */
-#include <stdint.h>
+/* IDX_MAX is the maximum value of an idx_t.  */
+#ifdef __PTRDIFF_MAX__
+# define IDX_MAX __PTRDIFF_MAX__
+#else
+# include <stdint.h>
+# define IDX_MAX PTRDIFF_MAX
+#endif
 
 /* The type 'idx_t' holds an (array) index or an (object) size.
    Its implementation promotes to a signed integer type,
@@ -127,10 +133,12 @@ extern "C" {
 /* Use the signed type 'ptrdiff_t'.  */
 /* Note: ISO C does not mandate that 'size_t' and 'ptrdiff_t' have the same
    size, but it is so on all platforms we have seen since 1990.  */
+#ifdef __PTRDIFF_TYPE__
+typedef __PTRDIFF_TYPE__ idx_t;
+#else
+# include <stddef.h>
 typedef ptrdiff_t idx_t;
-
-/* IDX_MAX is the maximum value of an idx_t.  */
-#define IDX_MAX PTRDIFF_MAX
+#endif
 
 /* So far no need has been found for an IDX_WIDTH macro.
    Perhaps there should be another macro IDX_VALUE_BITS that does not