C++ code will not compile

Sisyphus sisyphus1 at optusnet.com.au
Mon Mar 6 04:31:25 CET 2006


----- Original Message ----- 
From: "Greg Davis" <khiloa at gmail.com>
To: <gmp-discuss at swox.com>
Sent: Monday, March 06, 2006 4:47 AM
Subject: C++ code will not compile


> Hi guys,
>
> I got this code from some forums:
>
> #include <iostream>
> using namespace std;
> #include <gmp.h>
>
> int main()
> {
> mpz_t x;
> unsigned int y=126976;
> mpz_init(x);
> mpz_set_ui(x,4294967296);
> cout << "\nx: " <<x << endl;
> cout << "\ny: " <<y << endl ;
> mpz_pow_ui(x, x, y);
> cout << "x^y is  " << x << endl;
> mpz_clear(x);
> }
>
> but when I try to compile it I get:
>
> bignum.cpp:11: error: integer constant is too large for "long" type
>

I don't think this has anything to do with GMP - and such questions ought
not really be asked here.

On your machine, as with mine, '4294967296' is too large a number (33 bits)
to store as a "long" type. Apparently that's not the case on the other
machine - either that, or it's simply being ignored by the compiler .... or
it generated a warning instead of an error, and assigned '0'. Try:

mpz_set_ui(x, 4294967295); // a 32-bit number
mpz_add_ui(x, x, 1);

Cheers,
Rob



More information about the gmp-discuss mailing list