Look out the output:
1. When no O2 option set, the output is:
send out: 500000 Time: 1165250900
2. When -O2 option is set, the output is:
192.168.1.1 send out: 500000 Time: 1165250934
It proves that the execution sequence has been changed. I think it's a block bug, due to the reason that I can not control the execution flow, I had disabled -O2 optimization, but that's a big performance discount to my program.
// fake define
int nStartTime = 100;
int nTotalSendOut = 500000;
int nLastCalc = 10000000;
int now = time(NULL);
std::cout << "send out: " << nTotalSendOut << " Time: " << now - nLastCalc << std::endl;
float downspeed = 100000;
std::cout << "192.168.1.1" << "\t" << CalcDownSpeed() << std::endl;
Created attachment 13301 [details]
The sample code show the bug.
You are relying on undefined behavior.
*** This bug has been marked as a duplicate of 11751 ***