I have macro called energy_estimation.C which is given below,
void energy_estimation()
{
const int n=281877;
double part[n] ,energy[n],coredist[n] ,theta[n];
cout<< “hi”<< endl;
}
It is not working in root version 6.06 (crashing), however it works in version 5.34 of root and gives the output ‘hi’.
Interestingly,the macro works in 6.06 if I remove the array theta[n]
Don’t use variable length arrays (VLAs). It’s a bad idea!
You are allocating 281877 * 4 variables * sizeof(double) = 9,020,064, i.e. 9 MB of memory. The variables will be allocated on the stack - and that will most likely overflow. To me, the bug is in your code.
Use std::vector instead. Or use unique_ptr.
auto part = vector<double>(n);
// or if you dont want a vector:
auto part = unique_ptr<double[]>(new double[n]);
//or, as soon as you can use C++14:
auto part = make_unique<double[]>(n);