[英]Why does this code using __LINE__ compile under MSVC in Release mode, but not in Debug mode?
[英]Why does this code execute two branches of if…else in VS Debug mode
我在調試vs2013 / 2015/2008中的一些代碼時遇到了一些問題。
#include <iostream>
using namespace std;
int main()
{
int mode = 1;
int size = 1;
if (mode == 0)
{
cout << "mode = 0" << endl;
}
else
{
if (mode == 1)
{
if (size > 0)
{
cout << "mode=1,size=1" << endl; //in debug mode will execute this sentence
}
else
return 0; //however,when I Step in (F10),this will also be executed but have no influence.But When I insert a breakpoint in there and press F5, will not break in there
}
else if (mode == 2)
{
if (size > 0)
{
cout << "mode=2,size=1" << endl;
}
else
return 0;
}
}
return 1;}
那么,如何解釋這種現象呢? 有什么問題嗎? 我該如何解決?
這就是調試器在VS 2015中的工作方式。忽略它。
return 0;
沒有執行,即使它看起來像。 奇怪的行為,我也對此感到驚訝。
他們應該讓箭頭轉到else
語句,而不是它之后的第一行,但由於某種原因他們沒有。
只是忽略它。 如果你想要,你也可以提出功能要求:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.