RE: [ROOT] dynamic allocation and string

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Mar 14 2002 - 19:58:11 MET


> void main() {
>   int n=3;
>   int nn[n];
> }

This is not proper C++ (at least not yet ... I think this is possible with the
newer C standard).  Instead you consider using:

void main() {
   int n=3;
   int *nn = new int[n];
   // do something
   delete [] nn;
}

You might also want to consider using the existing variable length container
for this purpose. i.e. either TArrayI or std::vector.

> Unfortunatly at the end of my macro I get the following error:
> ----------
> *** Break *** segmentation violation
> Root > Function faitree_obj_dev() busy flag cleared
> Function c_str() busy flag cleared
> Function length() busy flag cleared

Hard to figure out what happened without more details.  The likely causes
is that something is being either access after being deleted or deleted
twice.

Cheers,
Philippe.


-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Tommaso Chiarusi
Sent: Thursday, March 14, 2002 12:34 PM
To: Root Newsgroup
Subject: [ROOT] dynamic allocation and string



Hi all,
1) 
since with the following simple macro

void main()
{
  int n=3;
  int nn[n];
}

I get the following error:

------------------
Error: Non-static-const variable in array dimension FILE:provafile.C 
LINE:47
 (cint allows this only in interactive command and special form macro 
which
  is special extension. It is not allowed in source code. Please ignore
  subsequent errors.)
*** Interpreter error recovered*** 
------------------

Which is the special extension I must give to my macro to abilitate 
dynamic allocation memory?

2) Since I need to manipulate arrays of strings, instead to use the 
C-style string (char p or char *p) I must use Class <string>.
The fact is that I manipulate filenames, which I must pass to TTree 
constructor, which need old C-style strings.
Then I use the c_str() method to convert a <string> to a C-string.
Unfortunatly at the end of my macro I get the following error:

----------
*** Break *** segmentation violation
Root > Function faitree_obj_dev() busy flag cleared
Function c_str() busy flag cleared
Function length() busy flag cleared
----------

My macro does what it must do, bu after that I have to quit ROOT and 
restart.

What's wrong?

Cheers, Tommaso



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:45 MET