Hi, i have a program that runs for severel hours and i'm using the clock function to extract some time data. But I recently notice some weird values and through debugging I found out that sometimes the clock funtion is returning a negative value that is messing my calculations. Does anyone know how can I fix this issue?
In http://cplusplus.com/reference/clibrary/ctime/clock/ it is written that clock may return -1. Also, if you're storing your time in a type smaller than clock_t this could happen. Other than that, I have no ideas.
In my case I'm sure it's not returning -1 and I don't know if it's a matter of variable type either, cause I'm storing in a float variable that I think it's big enought for the return of clock function. Besides i also have put the return of clock() in a debug watch and I still get a negative number.
The only way I could make this work was by casting the calc (clock()-beginTtime) to double, otherwise it doesn't work. I guess without the cast it tries to make all the calculations converting the values to int.