Hi Paul, > Why not default GCD_WORD_T to unsigned long long int? Existing usages > will work and this will be less hassle (and likely less error-prone) for > usages.
Doing so would be overkill on 32-bit platforms. 64-bit arithmetic on i386, for example, uses many registers and thus becomes slow. > Alternatively, use _Generic (if C) and/or sizeof (if not) to > make gcd a macro that "just works" for arbitrary integer types. If I did this, I would - either have two copies of the gcd code in libgettextlib, - or have to distinguish two different modules 'gcd' and 'llgcd' (like we do e.g. for 'ffs', 'ffsl', 'ffsll'). In the 'stdbit' module, things are simpler, because everything is inline. But when the code is not inlined, one needs a way to avoid or control extra copies of the code. (This problem also exists in C++: For templates that are entirely inlined, like e.g. lib/gl_list.hh, there is no worry. But otherwise, one needs explicit template instantiations.) > If the includer #defines GCD_WORD_T it should be the includer's > responsibility to make sure the definition works, which means the > #includes here are not needed. Yes, in theory this would be the good approach. But the using package can then not compile gcd.c, but needs to instead compile a file whose contents is #include <stddef.h> // or <stdint.h> #include "gcd.c" This extra file is added complexity, that I wanted to avoid. > Might want to mention in the gcd.h comments that different parts of an > application must all use the same GCD_WORD_T. Also, that GCD_WORD_T must > be an integer type (either signed or unsigned). Good points. Yes, there would be trouble if parts of the application see a declaration with type 'unsigned long' and other parts see it with 'uintmax_t'. There it's best to define it in <config.h>. But since <config.h> is not suppose to #include <stddef.h> or <stdint.h>, the current solution is probably the best compromise. 2025-06-22 Bruno Haible <br...@clisp.org> gcd: Improve comments regarding GCD_WORD_T. Reported by Paul Eggert in <https://lists.gnu.org/archive/html/bug-gnulib/2025-06/msg00243.html>. * lib/gcd.h (GCD_WORD_T): Improve comments. diff --git a/lib/gcd.h b/lib/gcd.h index 24b8ad54bf..ee05b39d21 100644 --- a/lib/gcd.h +++ b/lib/gcd.h @@ -20,6 +20,11 @@ /* Before including this file, you may define: GCD_WORD_T The parameter type and result type of the gcd function. + It should be an unsigned integer type that is either + a built-in type or defined in <stdef.h> or <stdint.h>. + + The definition of GCD_WORD_T needs to be the same across the entire + application. Therefore it is best placed in <config.h>. */ #ifdef GCD_WORD_T