i在我的程序中,我发现当is时循环无法正确退出int32_t。看起来像是整数溢出,并且远大于10,并且循环不会停止。请告诉我发生了什么以及如何在大型项目中避免此错误。
#include <iostream>
#include <stdint.h>
int f(int n){
for (int32_t i = 0; i < 10; ++i)
{
int64_t time = 4500000000 + (i) * 500000000;
std::cout << time<< " i: " << i << std::endl;
}
return 0;
}
int main ()
{
return f(10);
}
Run Code Online (Sandbox Code Playgroud)
c++ ×1