c++ interface: operator difficulties

cusp form cuspform at hotmail.com
Wed Aug 4 21:28:41 CEST 2004


hi,
A simple program to use gmp's c++ interface (4.1.3) segfaults when it 
attempt to use the overloaded operators.  I have no clue what it's doing 
wrong.

the code:

//### testgmp.cc ###//

#include <iostream>
#include <gmpxx.h>
using namespace std;
int main(void)
{
  mpf_class a (1.5);
  mpf_class b (3.0);
  mpf_class c (0.0);
  cout <<a<<endl;
  cout <<b<<endl;
  cout <<c<<endl;

  c = a+b;  //offending line

return 0;
}

****
the output:

1.5
3
0
Segmentation fault


****

The program is compiled using:
g++ testgmp.cc -lgmpxx -lgmp -g -gdwarf-2 -g3

****
uname -a says:
Linux localhost.localdomain 2.4.20-6 #1 Thu Feb 27 10:06:59 EST 2003 i686 
i686 i386 GNU/Linux
****
./config.guess says:
pentium4-pc-linux-gnu

****

gcc -v says:

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
--infodir=/usr/share/info --enable-shared --enable-threads=posix 
--disable-checking --with-system-zlib --enable-__cxa_atexit 
--host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

****
a bt in gdb says:

#0  0x00000000 in ?? ()
#1  0x400288fe in __gmpf_get_prec (x=0xbfffe8c0) at get_prc.c:27
#2  0x08048ad8 in __gmp_set_expr<__gmp_binary_expr<__gmp_expr<__gmpf_value, 
__gmpf_value>, __gmp_expr<__gmpf_value, __gmpf_value>, __gmp_binary_plus> > 
(
    f=0xbfffe8c0, expr=@0xbfffe8b8) at gmpxx.h:3186
#3  0x08048aa0 in operator=<__gmpf_value, 
__gmp_binary_expr<__gmp_expr<__gmpf_value, __gmpf_value>, 
__gmp_expr<__gmpf_value, __gmpf_value>, __gmp_binary_plus> > 
(this=0xbfffe8c0, expr=@0xbfffe8b8) at gmpxx.h:2790
#4  0x08048962 in main () at testgmp.cc:19
#5  0x42015504 in __libc_start_main () from /lib/tls/libc.so.6

****
and a frame 1 list gives

22      #include "gmp.h"
23      #include "gmp-impl.h"
24
25      unsigned long int
26      mpf_get_prec (mpf_srcptr x)
27      {
28        return __GMPF_PREC_TO_BITS (x->_mp_prec);
29      }


****
gmp was compiled using

./configure --enable-mpfr --enable-cxx --disable-shared



I apologize if this should have been sent to bugs, but I am not sure it is a 
bug.

by the way, does anybody use  #gmp on freenode?

thanks,
cuspform_

_________________________________________________________________
Overwhelmed by debt? Find out how to ‘Dig Yourself Out of Debt’ from MSN 
Money. http://special.msn.com/money/0407debt.armx



More information about the gmp-discuss mailing list