[SOLVED] Strange behavior of array of doubles

I am very lucky to finding many problems in short apps (via [SOLVED] Array of TVectorDs inside for loop cause crash ).

This time I have problem with array of doubles. If I declare it like it is shown in line 28 (see attached sources):

double averages[128];

then result is very surprising for me. Firstly I fill this array in for-loop and just after this I printout its value (smart macro PR(averages[j]). But after exiting from this for-loop I print out this array again and then first three values are wrong!

// ... something here +DEBUG: averages[j] = |132.691| +DEBUG: averages[j] = |135| +DEBUG: averages[j] = |140.336| +DEBUG: averages[j] = |133.811| +DEBUG: averages[j] = |132.113| +DEBUG: averages[j] = |131.338| +DEBUG: averages[j] = |134.39| // ... something else here +DEBUG: averages[k] = |499.677| +DEBUG: averages[k] = |135.773| +DEBUG: averages[k] = |2.1571| +DEBUG: averages[k] = |133.811| +DEBUG: averages[k] = |132.113| +DEBUG: averages[k] = |131.338| +DEBUG: averages[k] = |134.39| // ... and more here

When I declare the same array using operator new (line 27), then both results are equal. It is very confusing for me, specially I would never expect that g++ (it was run both, compiled and interpreted mode) is going to change values in memory, specially when nothing (what I declared) overlap this memory range.

Probably there is a way to debug it using valgrind, bus I am not to much familiar with it, so if somebody could help me and give a example of option I should put to valgrind to do it effective.

Best,
Rafal
scurve_calib.cxx (3.15 KB)

you forgot to post your data file

Rene

You mean input root file? I think it doesn’t matter because file is read correct and array is filled correct, problem is later after for-loop so it has nothing to do with root file.

Maybe I didn’t write it clearly in first post; when I use operator ‘new’ then values in array are OK. Only stack-version gives wrong results.

Best,
Rafal

Thanks to Rene problem is solved.

Description here: [SOLVED] Array of TVectorDs inside for loop cause crash

Best,
Rafal