Help regarding gmp programme.

Krishna Prasad kprasad.iitd at gmail.com
Sun Mar 1 11:37:13 CET 2009


Dear gmp users
                            I am krishna Prasad from department of
mathematics, Indian Institute of Technology Delhi, India .

                           I am new to this group and try to learn gmp
function. and i write a simple programme as given in the manual of gmp, this
will generate a error, these are my programme :

krishna at linux-u9op:~/Generalprog> vi krish1.cc


#include<iostream>
#include<stdio.h>
#include<gmp.h>
using namespace std;
int
main(void)
{
mpz_t a,b,c;
mpz_init(c);
gmp_printf("enter the large no.");
gmp_scanf("%Zd",a);
gmp_scanf("%Zd",b);
mpz_add(c,a,b);
gmp_printf("Sum is %Zd",c);
}



When i compile this as


krishna at linux-u9op:~/Generalprog> g++ krish1.cc -lgmpxx -lgmp
krishna at linux-u9op:~/Generalprog> ./a.out
enter the large no.234123445
*** glibc detected *** ./a.out: realloc(): invalid pointer: 0xb7fdd650 ***
======= Backtrace: =========
/lib/libc.so.6[0xb7d77fc4]
/lib/libc.so.6(realloc+0x280)[0xb7d7c7c0]
/lib/libc.so.6(realloc+0x3c)[0xb7d7c57c]
/usr/local/lib/libgmp.so.3(__gmp_default_reallocate+0x2b)[0xb7f79c0b]
/usr/local/lib/libgmp.so.3(__gmp_doscan+0xcec)[0xb7fa698c]
./a.out(__gxx_personality_v0+0x12a)[0x80487ce]
./a.out(__gxx_personality_v0+0x249)[0x80488ed]
./a.out[0x8048600]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:0a 33590
/home/krishna/Generalprog/a.out
08049000-0804a000 r--p 00000000 08:0a 33590
/home/krishna/Generalprog/a.out
0804a000-0804b000 rw-p 00001000 08:0a 33590
/home/krishna/Generalprog/a.out
0804b000-0806c000 rw-p 0804b000 00:00 0          [heap]
b7d0a000-b7d0c000 rw-p b7d0a000 00:00 0
b7d0c000-b7e49000 r-xp 00000000 08:09 186191     /lib/libc-2.8.so
b7e49000-b7e4b000 r--p 0013d000 08:09 186191     /lib/libc-2.8.so
b7e4b000-b7e4c000 rw-p 0013f000 08:09 186191     /lib/libc-2.8.so
b7e4c000-b7e4f000 rw-p b7e4c000 00:00 0
b7e4f000-b7e5b000 r-xp 00000000 08:09 185890     /lib/libgcc_s.so.1
b7e5b000-b7e5c000 r--p 0000b000 08:09 185890     /lib/libgcc_s.so.1
b7e5c000-b7e5d000 rw-p 0000c000 08:09 185890     /lib/libgcc_s.so.1
b7e5d000-b7e81000 r-xp 00000000 08:09 186201     /lib/libm-2.8.so
b7e81000-b7e82000 r--p 00023000 08:09 186201     /lib/libm-2.8.so
b7e82000-b7e83000 rw-p 00024000 08:09 186201     /lib/libm-2.8.so
b7e83000-b7f68000 r-xp 00000000 08:09 227147
/usr/lib/libstdc++.so.6.0.10
b7f68000-b7f6c000 r--p 000e5000 08:09 227147
/usr/lib/libstdc++.so.6.0.10
b7f6c000-b7f6d000 rw-p 000e9000 08:09 227147
/usr/lib/libstdc++.so.6.0.10
b7f6d000-b7f73000 rw-p b7f6d000 00:00 0
b7f73000-b7faa000 r-xp 00000000 08:09 303423
/usr/local/lib/libgmp.so.3.4.4
b7faa000-b7fab000 r--p 00036000 08:09 303423
/usr/local/lib/libgmp.so.3.4.4
b7fab000-b7fac000 rw-p 00037000 08:09 303423
/usr/local/lib/libgmp.so.3.4.4
b7fac000-b7faf000 r-xp 00000000 08:09 227441     /usr/lib/libgmpxx.so.4.0.2
b7faf000-b7fb0000 r--p 00002000 08:09 227441     /usr/lib/libgmpxx.so.4.0.2
b7fb0000-b7fb1000 rw-p 00003000 08:09 227441     /usr/lib/libgmpxx.so.4.0.2
b7fb1000-b7fb2000 rw-p b7fb1000 00:00 0
b7fcd000-b7fcf000 rw-p b7fcd000 00:00 0
b7fcf000-b7fea000 r-xp 00000000 08:09 186288     /lib/ld-2.8.so
b7fea000-b7feb000 r--p 0001a000 08:09 186288     /lib/ld-2.8.so
b7feb000-b7fec000 rw-p 0001b000 08:09 186288     /lib/ld-2.8.so
bfed7000-bfeec000 rw-p bffeb000 00:00 0          [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]
Aborted
krishna at linux-u9op:~/Generalprog>


any one can help me,

thanks in advance.

Best regard

Krishna Prasad
IIT Delhi
India
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gmplib.org/list-archives/gmp-discuss/attachments/20090301/684e03a8/attachment.html>


More information about the gmp-discuss mailing list