A little warning in GMP.h

Francesco Montorsi f18m_cpp217828 at yahoo.it
Wed Sep 22 18:42:48 CEST 2004


Hi,
  I'm using GMP with various win32 compilers and I've found that most of them report a warning like this about gmp.h:

c:\gmp\gmp.h(1599) : warning C4146: unary minus operator applied to unsigned type, result still unsigned

Since I'm including GMP.h in every file of my project, I would like to solve this warning (at least on my local copy of GMP !)... :-)
Unfortunately I could not completely understand what line 1599 does: this is an extract from GMP.h:


#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui)
#if ! defined (__GMP_FORCE_mpz_get_ui)
__GMP_EXTERN_INLINE
#endif
unsigned long
mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
  mp_ptr __gmp_p = __gmp_z->_mp_d;
  mp_size_t __gmp_n = __gmp_z->_mp_size;
  mp_limb_t __gmp_l = __gmp_p[0];
  if (__GMP_ULONG_MAX <= GMP_NUMB_MASK)
    return __gmp_l & (-(mp_limb_t) (__gmp_n != 0));
#if GMP_NAIL_BITS != 0 /* redundant #if, shuts up compiler warnings */
  else   /* happens for nails, but not if LONG_LONG_LIMB */
    {   /* assume two limbs are enough to fill an ulong */
      __gmp_n = __GMP_ABS (__gmp_n);
      if (__gmp_n <= 1)
 return __gmp_l & (-(mp_limb_t) (__gmp_n != 0));
      else
 return __gmp_l + (__gmp_p[1] << GMP_NUMB_BITS);
    }
#endif
}
#endif

(the line in bold is 1599); can I just cast that value to SIGNED without breaking the function ?
It would be something like:

return __gmp_l & (-(signed)(mp_limb_t) (__gmp_n != 0));


thanks for the help with this annoying warning,
FM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /list-archives/gmp-discuss/attachments/20040922/8d6f1ba4/attachment.htm


More information about the gmp-discuss mailing list