Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#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