# TString, stdarg, variable argument list?

**URL:** <https://root-forum.cern.ch/t/tstring-stdarg-variable-argument-list/15001>\
**Category:** ROOT\
**Created:** [September 28, 2012, 6:35pm UTC](https://root-forum.cern.ch/t/tstring-stdarg-variable-argument-list/15001 "2012-09-28T18:35:56Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![jfcaron](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jfcaron](https://root-forum.cern.ch/u/jfcaron)\
**Post date:** [September 28, 2012, 6:35pm UTC](https://root-forum.cern.ch/t/tstring-stdarg-variable-argument-list/15001/1 "2012-09-28T18:35:56Z")

</div>

Hi, I have a named ROOT macro which I want to use with a variable argument list (using stdarg, unless there is a better option).

The beginning of the macro is as follows:

```auto
void standard_analysis(TString path_to_dir, TString argformat, ...)
{ 
  cout << path_to_dir << argformat << endl;
  va_list args;
  va_start(args,argformat);
  
  Int_t integration_time = va_arg(args,Int_t);
  Int_t cc_frames = va_arg(args,Int_t);
  Double_t cc_thresh = va_arg(args,Double_t);

  va_end(args);
```

For now I am hard-coding the access of the arguments and ignoring the format string, because this is being converted from older code which had fixed arguments.

The macro compiles, but a problem arises when I try to pass the TString arguments just using “strings”:

```auto
standard_analysis("../rootfiles/Outputs/Run0464","iif",8000,50,0.007)

 ***Break*** segmentation violation
```

but if I define the TStrings separately, it works:

```auto
root [13] TString fmt("iif")
root [14] TString ptd("../rootfiles/Outputs/Run0464")
root [15] standard_analysis(ptd,fmt,8000,50,0.007)
../rootfiles/Outputs/Run0464iif
...
```

This means that when I run the macro from the command line with root -b standard\_analysis.C+(“path”,“format”,8000,50,0.007), I get the same segmentation fault as when using “strings”.

The older code looked like this:

```auto
void standard_analysis(TString path_to_dir, Int_t integration_time, Int_t cc_frames, Float_t cc_thresh){
```

and it worked fine passing the first argument either as a “string” or as an explicit TString, and also from the command line.

I’d appreciate any help in resolving this issue. I’d like to keep using TStrings because I do some manipulations in the code later to define paths.

Jean-François

---

_[View the full topic](https://root-forum.cern.ch/t/tstring-stdarg-variable-argument-list/15001)._
