Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > why the VC8 treat goto and switch-case different?

Reply
Thread Tools

why the VC8 treat goto and switch-case different?

 
 
miaohua1982@gmail.com
Guest
Posts: n/a
 
      11-27-2006
under the same warning level, the code is:

class X{
public:
X(){}
virtual void g(){}
};
void f(int i){
if(i<10)
goto jump1;
X x1;
jump1: //warning C4533: initialization of 'x1' is skipped by 'goto
jump1',why there is only a warning?

switch(i){
case 1:
X x2;
break;
case 2: //error C2360: initialization of 'x2' is skipped by 'case'
label
X x3;
break;
}
}

 
Reply With Quote
 
 
 
 
Bo Persson
Guest
Posts: n/a
 
      11-27-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> under the same warning level, the code is:
>
> class X{
> public:
> X(){}
> virtual void g(){}
> };
> void f(int i){
> if(i<10)
> goto jump1;
> X x1;
> jump1: //warning C4533: initialization of 'x1' is skipped by
> 'goto jump1',why there is only a warning?
>
> switch(i){
> case 1:
> X x2;
> break;
> case 2: //error C2360: initialization of 'x2' is skipped by
> 'case' label
> X x3;
> break;
> }
> }


The language standard doesn't say anything about different levels, it just
speaks of a 'diagnostic' required for certain faults. The rest is up to the
implementation, inluding any additional messages for these kinds of
constructs.

Most compilers have a setting like 'treat warnings as errors', to get away
with your problem.


Bo Persson


 
Reply With Quote
 
 
 
 
miaohua1982@gmail.com
Guest
Posts: n/a
 
      11-28-2006
Thank you very much!

"Bo Persson д
"
> (E-Mail Removed) wrote:
> > under the same warning level, the code is:
> >
> > class X{
> > public:
> > X(){}
> > virtual void g(){}
> > };
> > void f(int i){
> > if(i<10)
> > goto jump1;
> > X x1;
> > jump1: //warning C4533: initialization of 'x1' is skipped by
> > 'goto jump1',why there is only a warning?
> >
> > switch(i){
> > case 1:
> > X x2;
> > break;
> > case 2: //error C2360: initialization of 'x2' is skipped by
> > 'case' label
> > X x3;
> > break;
> > }
> > }

>
> The language standard doesn't say anything about different levels, it just
> speaks of a 'diagnostic' required for certain faults. The rest is up to the
> implementation, inluding any additional messages for these kinds of
> constructs.
>
> Most compilers have a setting like 'treat warnings as errors', to get away
> with your problem.
>
>
> Bo Persson


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Building extensions with vc8 Howard Lightstone Python 1 01-22-2007 09:48 PM
Why must Firefox nag me and treat me like an idiot? Janice P. Firefox 8 01-02-2007 07:27 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
problem reading integers separated by commas with VC8 andreas.fabri@geometryfactory.com C++ 4 03-10-2006 09:22 PM
boost::bind problem in VC8 IndyStef C++ 2 11-30-2005 03:47 PM



Advertisments