RE: [ROOT] Problem with <complex> when using compiled library

From: Philippe Canal (pcanal@popgtw.fnal.gov)
Date: Thu Nov 30 2000 - 01:10:47 MET


Hi Malcolm,

Currently in the standard release of ROOT, cint uses an interpreted version
of the complex class rather than a compiled version.

This means that when you are at the intrepter level and do a #include <complex>,
this loads a script defining "a" complex class.

On the other hands, when you compile your file IEM_TEST.cpp, all your routines
are creating for a compiled version of the complex class (the one coming with
your compiler).  

However, the interpreter is not really aware of this difference.

So when you are using your compiled library, and call:

   iem.setEPS(complex<float>(10.0,0.1));

from the interpreter, your function is passed the "interpreter version"
of a complex and thus core dumps (since it expects the compiled version which
is different).

Philippe.




> -----Original Message-----
> From: owner-roottalk@pcroot.cern.ch
> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Malcolm Davidson
> Sent: Monday, November 27, 2000 3:06 AM
> To: roottalk@pcroot.cern.ch
> Subject: [ROOT] Problem with <complex> when using compiled library
> 
> 
> Hello,
> 
> I'm having trouble using a class definition containing complex numbers
> when it is compiled as a shared library using CINT. The definition works
> fine in interpreted mode. I've included examples below. For the record I
> am using Mandrak Linux 7.2 and ROOT v2.25 which I compiled from sources.
> 
> Many thanks in advance for your help.
> 
> Malcolm
> 
> **************************************************
> Interpreted result
> **************************************************
> root [2] .L /home/davidson/root/macros/test/IEM_TEST.cpp
> root [3] IEM iem;
> root [4] iem.print_par();
> => Dielectric constant = (3,0.1) // OK
> root [5] iem.setEPS(complex<float>(10.0,0.1))
> root [6] iem.print_par();
> => Dielectric constant = (10,0.1) // OK
> 
> **************************************************
> Using compiled library
> **************************************************
> root [15] .L /home/davidson/root/macros/test/IEM_TEST.cpp+
> Creating shared library /home/davidson/root/macros/test/IEM_TEST.so
> Note: operator new() masked 1c
> Note: operator delete() masked 1c
> Class IEM: Streamer() not declared
> Class IEM: ShowMembers() not declared
> 
> root [16] .x /home/davidson/root/macros/test/TEST.cpp
> Warning: File "iostream.h" already loaded
> Dielectric constant = (3,0.1) //OK
> Dielectric constant = (5.35546,5.35546) //WRONG should be (10,0.1)
> 
> Here are the class definition and script
> **************************************************
> IEM_TEST.cpp
> **************************************************
> #include <complex>
> #include <iostream.h>
> class IEM {
>  public:
>   IEM();
>   void setEPS(const complex<float>&);
>   void print_par();
> 
> private:
>     complex<float> eps;
> };
> 
> IEM::IEM() {
>     eps=complex<float>(3.0,0.1);
> }
> inline void IEM::setEPS(const complex<float>& eps_in) {
>   eps=eps_in;
> }
> void IEM::print_par(){
>   cout << "Dielectric constant = " << eps << endl;
> }
> 
> **************************************************
> Calling function
> **************************************************
> 
> {
> gROOT->Reset();
> 
> #include<iostream.h>
> #include<complex>
> 
> IEM iem;
> complex<float> eps;
> 
> iem.print_par();
> iem.setEPS(complex<float>(10.0,0.1));
> iem.print_par();
> }
> 
> 
> 
> 
> <>------------------------------------------------<>
> Malcolm W. J. Davidson
> 
> Centre D'Etudes Spatiales de la Biosphere (CESBIO)
> UMR 5639 CNES-CNRS-UPS
> 18, Avenue Edouard Belin
> F-31401 Toulouse Cedex 4
> FRANCE
> 
> e-mail : davidson@cesbio.cnes.fr
> phone (33)(0)5.61.55.85.84
> fax   (33)(0)5.61.55.85.00
> <>------------------------------------------------<>
> 
> 
> 
> 



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:38 MET