当前位置:网站首页>The difference between debug and release

The difference between debug and release

2022-07-04 23:07:00 Programming segment

We are using Visual Studio compile cpp Code , There will be debug and release Two modes , So what's the difference between these two modes ?

Say first conclusion :
Generally in the development process , We often write code with bug, For the convenience of debugging , Will choose debug Mode to compile , The purpose is not to let the compiler optimize or optimize less ; But when the version needs to be released after development , In order to make the generated machine code run faster , Often choose release Pattern , In this way, the compiler will help us compile and optimize as much as possible .

Let's explain why
for example , We wrote a piece of code , Calculate from 0 Add to 999 Value , If you don't use compiler optimization , Then the generated assembly code is shown in the right half .

int main()
{
    
    int res;
    for(int i=0; i<1000; i++)
    {
    
        res += i;
    }
    return res;
}

 Insert picture description here
however , If used -O3 Level compiler optimization ( The greater the number , The higher the optimization level ), Then the generated assembly code becomes as follows . Because the compiler analysis found that this code is the return 499500 This value , So it will be optimized into such assembly code , Obviously, it runs much faster . But if we need to for In cycle debug During debugging , The compiler will not find such code , Because there is no assembly code for loop , So I won't debug . But the code without optimization can be in for Debug inside the loop .
 Insert picture description here

 Insert picture description here

原网站

版权声明
本文为[Programming segment]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207042237023943.html