2 minor issues on Windows

Niels Möller nisse at lysator.liu.se
Thu Feb 3 08:50:14 CET 2022


George Woltman <woltman at alum.mit.edu> writes:

> 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.

Hi, looking through old mail, sorry for the late reply.

> 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.

That's kind-of difficult. I agree it would make sense to increase size
of mp_bitcnt_t (perhaps ptrdiff_t would be a reasonable and portable
definition?), but it's going to be an ABI break platforms where that's an
actual change of size. Torbjörn, should this be listed under the things
to fix once we decide to break ABI compatibility?

Do you also get a 32-bit mp_size_t ?

> 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

I can only suggest that you disable or ignore that warning. Operations
on unsigned types is well defined by the C standard, and gmp depends on
practically all possible cornercases to work according to spec.

Regards,
/Niels

-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-bugs mailing list