2 minor issues on Windows

George Woltman woltman at alum.mit.edu
Thu Nov 25 19:02:13 CET 2021


Hi,

I'm using GMP 6.2.  Has been working fine for 2+ years now, great library.

I've built the library (64-bit) using Cygwin.  This creates a DLL and a
gmp.h file that can be used with Microsoft Visual Studio C compiler.
As you probably know, MSVC strangely defines long as 32-bits.

In gmp.h, these lines appear:

#ifdef __GMP_SHORT_LIMB
typedef unsigned int mp_limb_t;
typedef int mp_limb_signed_t;
#else
#ifdef _LONG_LONG_LIMB
typedef unsigned long long int mp_limb_t;
typedef long long int mp_limb_signed_t;
#else
typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
#endif
#endif
typedef unsigned long int mp_bitcnt_t;

The problem is that while _LONG_LONG_LIMB is defined, the definition of
mp_bitcnt_t ought to also use "long long".
I get this compiler warning calling mpz_tstbit:  warning C4244: 'argument':
conversion from 'uint64_t' to 'mp_bitcnt_t', possible loss of data
Yes, I'm creating mpz values with more than 4 billion bits.

Minor issue #2 (I should have reported this years ago, sorry):

In gmp.h, these lines:

mpn_neg (mp_ptr __gmp_rp, mp_srcptr __gmp_up, mp_size_t __gmp_n)
{
  while (*__gmp_up == 0) /* Low zero limbs are unchanged by negation. */
    {
      *__gmp_rp = 0;
      if (!--__gmp_n) /* All zero */
return 0;
      ++__gmp_up; ++__gmp_rp;
    }

  *__gmp_rp = (- *__gmp_up) & GMP_NUMB_MASK;

The last line generates this compiler warning:
warning C4146: unary minus operator applied to unsigned type, result still
unsigned

Let me know if you need any more info.

Regards,
George Woltman


More information about the gmp-bugs mailing list