From: Bruno Haible Date: Sun, 22 Jun 2025 20:12:23 +0000 (+0200) Subject: gcd: Allow customizing the parameter and result type. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f87265a9e0fc89bff0c55360c0cac6dccda1b705;p=thirdparty%2Fgnulib.git 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/ChangeLog b/ChangeLog index bf1fea6a05..7b5ded386a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2025-06-22 Bruno Haible + + 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. + 2025-06-18 Bruno Haible string-desc: Fix a compiler warning. 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 +# include +#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