why the VC8 treat goto and switch-case different?

M

miaohua1982

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;
}
}
 
B

Bo Persson

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
 
M

miaohua1982

Thank you very much!

"Bo Persson дµÀ£º
"
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top