+2020-12-17 Paul Eggert <eggert@cs.ucla.edu>
+
+ idx: simplify IDX_MAX, remove IDX_WIDTH
+ * lib/idx.h (IDX_MAX): Simplify by removing obsolete reference
+ to UNSIGNED_IDX_T.
+ (IDX_WIDTH): Remove, since it’s not used and its value
+ arguably should be PTRDIFF_WIDTH anyway.
+
2020-12-16 Bruno Haible <bruno@clisp.org>
posix_spawn_file_actions_addfchdir-tests: Rename test.
/* Get ptrdiff_t. */
#include <stddef.h>
-/* Get PTRDIFF_WIDTH. */
+/* Get PTRDIFF_MAX. */
#include <stdint.h>
/* The type 'idx_t' holds an (array) index or an (object) size.
- Its implementation is a signed integer type, capable of holding the values
+ Its implementation promotes to a signed integer type,
+ which can hold the values
0..2^63-1 (on 64-bit platforms) or
0..2^31-1 (on 32-bit platforms).
or to the C standard. Several programming languages (Ada, Haskell,
Common Lisp, Pascal) already have range types. Such range types may
help producing good code and good warnings. The type 'idx_t' could
- then be typedef'ed to a (signed!) range type. */
+ then be typedef'ed to a range type that is signed after promotion. */
-#if 0
-/* In the future, idx_t could be typedef'ed to a signed range type. */
-/* Note: The clang "extended integer types", supported in Clang 11 or newer
+/* In the future, idx_t could be typedef'ed to a signed range type.
+ The clang "extended integer types", supported in Clang 11 or newer
<https://clang.llvm.org/docs/LanguageExtensions.html#extended-integer-types>,
are a special case of range types. However, these types don't support binary
operators with plain integer types (e.g. expressions such as x > 1).
Therefore, they don't behave like signed types (and not like unsigned types
either). So, we cannot use them here. */
-typedef <some_range_type> idx_t;
-#else
-/* Use the signed type 'ptrdiff_t' by default. */
+
+/* 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 an all platforms we have seen since 1990. */
+ size, but it is so on all platforms we have seen since 1990. */
typedef ptrdiff_t idx_t;
-#endif
/* IDX_MAX is the maximum value of an idx_t. */
-#if defined UNSIGNED_IDX_T
-# define IDX_MAX SIZE_MAX
-#else
-# define IDX_MAX PTRDIFF_MAX
-#endif
-
-/* IDX_WIDTH is the number of bits in an idx_t (31 or 63). */
-#define IDX_WIDTH (PTRDIFF_WIDTH - 1)
+#define IDX_MAX PTRDIFF_MAX
+
+/* So far no need has been found for an IDX_WIDTH macro.
+ Perhaps there should be another macro IDX_VALUE_BITS that does not
+ count the sign bit and is therefore one less than PTRDIFF_WIDTH. */
#endif /* _IDX_H */