GMP compile failure

Tim Hockin thockin at hockin.org
Mon Dec 31 06:07:40 CET 2007


That change does fix this problem.  I assume the same problem would
exist on binary_ior and binary_xor.

I have some other compile warnings that could maybe be solved
similarly - would such a change be considered for merging?

thanks!

Tim


On Dec 28, 2007 5:00 PM, Marc Glisse <marc.glisse at normalesup.org> wrote:
> On Fri, 28 Dec 2007, Tim Hockin wrote:
>
> > This (simplified) C++ snippet does not compile.  But it doesn't give
> > me the possibly-expected undefined operator error:
> >
> >                mpz_class foo(123);
> >                mpz_class bar = foo & 0x107;
> [...]
> > /usr/include/gmpxx.h:3413: error: invalid conversion from 'const long
> > int' to 'const __mpz_struct*'
> > /usr/include/gmpxx.h:3413: error:   initializing argument 3 of 'static
> > void __gmp_binary_and::eval(__mpz_struct*, const __mpz_struct*, const
> > __mpz_struct*)'
>
> Whereas just "foo & 0x107;" compiles fine.
>
> > I can make it build by explicitly casting the int to mpz_class, but
> > that's kind of a pain.  I am converting a codebase to use GMP, and
> > this is causing lots of errors.
>
> You can also modify struct __gmp_binary_and in gmpxx.h to (untested):
>
> struct __gmp_binary_and
> {
>    static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
>    { mpz_and(z, w, v); }
>    static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int i)
>    {
>        mpz_t temp;
>        mpz_init_set_ui(temp,i);
>        mpz_and(z, w, temp);
>        mpz_clear(temp);
>    }
>    static void eval(mpz_ptr z, unsigned long int i, mpz_srcptr w)
>    {
>        mpz_t temp;
>        mpz_init_set_ui(temp,i);
>        mpz_and(z, temp, w);
>        mpz_clear(temp);
>    }
> };
>
> But if you want to distribute your code, that is not a solution.
>
> > Is there any answer to this, other than "cast it"?
>
> I am not familiar enough with the code to know the right answer.
>
> > why such a cryptic error?
>
> Getting non-cryptic error messages in C++ is... hard. Here the code goes
> through many inline functions to try and avoid any useless copy and the
> type problem is detected only in the middle.
>
> --
> Marc Glisse
>


More information about the gmp-discuss mailing list