The 'gcd' module provides a gcd() function with 'unsigned long' parameters. But some packages (such as GNU gettext) need it with 'size_t' parameters. This matters, because on native Windows, 'size_t' is larger than 'unsigned long'. (Platforms where 'size_t' is smaller than 'unsigned long', such as Windows 3.1, are not relevant here.)
2025-06-22 Bruno Haible <br...@clisp.org> gcd: Allow customizing the parameter and result type. * lib/gcd.h (GCD_WORD_T): New type. (gcd): Use GCD_WORD_T instead of 'unsigned long'. * lib/gcd.c (WORD_T): Likewise. diff --git a/lib/gcd.c b/lib/gcd.c index 8a7fb8ed10..25170abfc6 100644 --- a/lib/gcd.c +++ b/lib/gcd.c @@ -22,7 +22,7 @@ #ifndef WORD_T /* Specification. */ # include "gcd.h" -# define WORD_T unsigned long +# define WORD_T GCD_WORD_T # define GCD gcd #endif diff --git a/lib/gcd.h b/lib/gcd.h index 02a8adccd9..24b8ad54bf 100644 --- a/lib/gcd.h +++ b/lib/gcd.h @@ -18,13 +18,25 @@ #ifndef _GCD_H #define _GCD_H +/* Before including this file, you may define: + GCD_WORD_T The parameter type and result type of the gcd function. + */ + +#ifdef GCD_WORD_T +/* Make sure that GCD_WORD_T is defined as a type. */ +# include <stddef.h> +# include <stdint.h> +#else +# define GCD_WORD_T unsigned long +#endif + #ifdef __cplusplus extern "C" { #endif /* Return the greatest common divisor of a > 0 and b > 0. */ -extern unsigned long gcd (unsigned long a, unsigned long b); +extern GCD_WORD_T gcd (GCD_WORD_T a, GCD_WORD_T b); #ifdef __cplusplus