Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   why the VC8 treat goto and switch-case different? (http://www.velocityreviews.com/forums/t458722-why-the-vc8-treat-goto-and-switch-case-different.html)

miaohua1982@gmail.com 11-27-2006 09:02 AM

why the VC8 treat goto and switch-case different?
 
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;
}
}


Bo Persson 11-27-2006 06:47 PM

Re: why the VC8 treat goto and switch-case different?
 
miaohua1982@gmail.com 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



miaohua1982@gmail.com 11-28-2006 05:26 AM

Re: why the VC8 treat goto and switch-case different?
 
Thank you very much!

"Bo Persson д
"
> miaohua1982@gmail.com 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




All times are GMT. The time now is 02:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.