Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualnoatom

Posted 23 April 2013 - 02:59 PM

According to one of my books,the following code should not work:

 

void f(){
	int ma;
	cin >> ma;
	if(ma == 10)
		goto heya;

	int x;
heya:
	cout << "a";
}

 

Why? Because the storage for x is allocated at the beginning of the code block,but if I type 10,then it will jump to heya,so,it will skip the definition,thus constructor call.

 

The code should generate a warning,or an error,but I got none.

 

The code + explanation is from Thinking in C++.

 

Is that concept still correct,or outdated?


#1noatom

Posted 23 April 2013 - 02:56 PM

According to one of my books,the following code should not work:

 

void f(){
	int ma;
	cin >> ma;
	if(ma == 10)
		goto heya;

	int x;
heya:
	cout << "a";
}

 

Why? Because the storage for x is allocated at the beginning of the code block,but if I type 10,then it will jump to heya,so,it will skip the constructor call.

 

The code should generate a warning,or an error,but I got none.

 

The code + explanation is from Thinking in C++.

 

Is that concept still correct,or outdated?


PARTNERS