Constructor taking 64-bit integer missing on (some) Windows C++ compilers
Vincent Lefevre
vincent at vinc17.net
Sat Jun 6 08:26:58 UTC 2020
On 2020-06-06 14:28:21 +1000, Mihai Preda wrote:
> I'm using libgmp-dev 6.1.2 on Ubuntu myself, but the bug report
> concerns an unspecified version of GMP on Windows. I have reasons to
> suspect the bug is valid for the most recent GMP. Clear cause analysis
> and proposed solution is included.
>
> I'm not a Windows user myself. I develop an open-source app that users
> are compiling, among others, on Windows with mingw or other c++
> compilers on windows. A common habit of these c++ compilers on windows
> is to have 32-bit long.
There's the same issue with 32-bit architectures, whatever the OS.
> In my app I construct a mpz_class from a 64-bit unsigned integer, like this:
> uint64_t h = ...;
> mpz_class{h};
>
> At this point the C++ compiler on windows (where long is 32-bit)
> reports errors, see at the end. The problem is that the set of
> constructors does not include one taking a 64-bit integer:
>
> #define __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS \
> __gmp_expr(signed char c) { init_si(c); } \
> __gmp_expr(unsigned char c) { init_ui(c); } \
> __gmp_expr(signed int i) { init_si(i); } \
> __gmp_expr(unsigned int i) { init_ui(i); } \
> __gmp_expr(signed short int s) { init_si(s); } \
> __gmp_expr(unsigned short int s) { init_ui(s); } \
> __gmp_expr(signed long int l) { init_si(l); } \
> __gmp_expr(unsigned long int l) { init_ui(l); } \
> __gmp_expr(float f) { init_d(f); } \
> __gmp_expr(double d) { init_d(d); }
>
> Among all in the list above, none takes a uint64_t or int64_t.
>
> The fix could consist in having these constructors take int64_t
> instead of long int, etc. I.e. take explicitly-sized typed instead of
> the "long" which is variable-size.
I would rather suggest to support intmax_t and uintmax_t.
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the gmp-bugs
mailing list