Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#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