简体   繁体   中英

Unregular running in debugging steps

I have a makefile project in Eclipse and when I debug the program the order of running steps is not regular. As an example in the following function, the commands will be run in this order: 1,6,1,6,1,... and it is supposed to be 6,7,8,.....

1    int  get_region(int x, int y, int level, int &region_x, int &region_y, int min_x,int min_y,int max_x,int max_y)
    {
2       int X_distance = max_x - min_x;
3       int Y_distance = max_y - min_y;
4       int steps_x = X_distance / (pow(2,level)) + 1; 
5       int steps_y = Y_distance / (pow(2,level)) + 1;

6       region_x =  (x - min_x) / steps_x;
7       region_y =  (y - min_y) / steps_y;

8       cout << "region_x = " << region_x << "  x = "<< x << endl;
9       cout << "region_y = " << region_y << "  y = "<< y << endl;

10      cout << "****************** get_region function is called  **************"<<endl;

11      return 0;
    }

That's normal behavior when your code is compiled with optimizations enabled. The compiler rearranges your code to get better performance out of it.

Compile with optimizations turned off to make the debugging easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM