Hi Damon,
It is seems that the string are not properly copied with the default
copy constructor provided by CINT.
To work around the problem, use a class and explicit copy constructor like
for example:
class SQLVariable_t {
public:
string table;
UInt_t id;
Char_t type;
string column;
SQLVariable_t() {};
SQLVariable_t(const SQLVariable_t& orig) {
table = orig.table;
id = orig.id;
type = orig.type;
column = orig.column;
};
};
Cheers,
Philippe.
P
-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Damon Spayde
Sent: Tuesday, September 25, 2001 10:10 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] Problems with string
The following piece of code suffers a segmentation violation when run via
the interpreter, but runs correctly when compiled and run with ACLiC as
shown below. I am developing a class that uses the SQLVariable_t struct
defined in the code chunk that I prototype with ACLiC, but I always get
error messages when I try to access the string members of the struct. Is
this a CINT limitation that I have to live with, a bug that must be fixed,
or an error on my part? Any help or insight would be appreciated. I am
using ROOT version 3.01/06 on RedHat 6.1.
Thanks,
Damon Spayde
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 3.01/06 22 August 2001 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
Compiled with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.06, June 30 2001
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
This ROOT was started by SAMPLE
root [0] .x SQLtest.C
temp.type = y
temp.id = 0
temp.table = measurement
temp.column = value
res.type = y
res.id = 0
res.table =
*** Break *** segmentation violation
Root > Function operator<<() busy flag cleared
Function SQLtest() busy flag cleared
root [1] .x SQLtest.C++
script has already been loaded in interpreted mode
Unloading /group/gzero/spayde/G0Analysis/sql/./SQLtest.C and compiling it
Creating shared library /group/gzero/spayde/G0Analysis/sql/./SQLtest_C.so
temp.type = y
temp.id = 0
temp.table = measurement
temp.column = value
res.type = y
res.id = 0
res.table = measurement
res.column = value
root [2]
//-------------------Begin File SQLtest.C-----------------------------
#include <string>
#ifndef __CINT__
#include "Rtypes.h"
#endif
using namespace std;
typedef struct SQLVariable_t {
string table;
UInt_t id;
Char_t type;
string column;
};
SQLVariable_t test(void) {
SQLVariable_t temp;
temp.id = 0;
temp.type = 'y';
temp.table = "measurement";
temp.column = "value";
cerr << "temp.type = " << temp.type << endl;
cerr << "temp.id = " << temp.id << endl;
cerr << "temp.table = " << temp.table << endl;
cerr << "temp.column = " << temp.column << endl;
cerr << endl;
return temp;
}
void SQLtest(void) {
SQLVariable_t res = test();
cerr << "res.type = " << res.type << endl;
cerr << "res.id = " << res.id << endl;
cerr << "res.table = " << res.table << endl;
cerr << "res.column = " << res.column << endl;
}
//----------------------End File SQLtest.C-----------------------------
-------------------------------------------------------------------------
Damon Spayde
University of Illinois at Urbana-Champaign
Jefferson Lab E-mail: spayde@jlab.org
Counting House Cubicle 16 Phone: (757) 269-5192
-------------------------------------------------------------------------
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:00 MET