Dear Victor Thank you, it seems the best way is to use new char. Best regards Christian Victor Perevoztchikov wrote: >>Is the following code allowed in other compilers: >> const Int_t kBufSize = 512; //in global space >> char option[kBufSize]; // in different functions > > This is legal. But this array will disapeared after return or outside of > scope. > Anyway you can use new char[size]. But then somewhere you must delete it, to > avoid memory leak; > Victor > > > Victor M. Perevoztchikov perev@bnl.gov > Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000 > tel office : 631-344-7894; fax 631-344-4206; > > ----- Original Message ----- > From: "cstrato" <cstrato@aon.at> > To: "Victor Perevoztchikov" <perev@bnl.gov> > Cc: <fine@bnl.gov>; "'Elias Athanasopoulos'" <elathan@phys.uoa.gr>; > <roottalk@pcroot.cern.ch> > Sent: Monday, June 07, 2004 3:02 PM > Subject: Re: [ROOT] compiler warning > > > >>Dear all >> >>Thank you all for giving me some more information. >> >>Sorrowly, Victor´s statement is really bad news. >>Is the following code allowed in other compilers: >> const Int_t kBufSize = 512; //in global space >> char option[kBufSize]; // in different functions >> >>To reply to Valeri: >>Suppose, I have the following code with the input: >> "options = "myopt1:myopt2" >> >> MyFunction(const char *option) >> { >> Int_t csize = strlen(options) + 1; >> char *opt = new char[csize]; >> char *opt1 = new char[csize]; >> char *opt2 = new char[csize]; >> >> opt = strtok(strcpy(opt, options),":"); >> opt1 = strcpy(opt1, opt); >> >> opt = strtok(NULL, ":"); >> opt2 = strcpy(opt2, opt); >> >> myClass->MyMethod(opt1, opt2) >> { >> fString1 = opt1; //TString fString1; >> fString2 = opt2; //TString fString2; >> } >> >> delete [] opt2; >> delete [] opt1; >> delete [] opt; >> } >>Is this code safe as long as I use TString and not char? >> >>BTW, this is the reason, why I always hated C which I >>have never used, and why I try to use the TString class >>whenever possible, :-) >> >>Best regards >>Christian >> >>
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET