473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

Nov 27 '06 #1
2 1960
mi*********@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
Nov 27 '06 #2
Thank you very much!

"Bo Persson дµÀ£º
"
mi*********@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
Nov 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Hayri ERDENER | last post by:
hi, what is the equivalent of C languages' goto statement in python? best regards
45
by: Debashish Chakravarty | last post by:
K&R pg.66 describes two situations when using goto makes sense. Has anyone here come across situations where using goto provided the most elegant solution. --...
22
by: Nimmi Srivastav | last post by:
Can someone kindly clarify the distinction between long jumps and gotos? Why is one frowned upon and not the other? Is there really any situation where use of longjmp becomes inevitable? A...
28
by: Vishal Naidu | last post by:
i m new to the C world... i ve been told by my instructors not to use goto stmt.. but no one could give me a satisfactory answer as to why it is so.. plz help me out of this dilemma, coz i use...
17
by: SUMIT | last post by:
I wrote a program for removing comment from C source file for which i... 1.first constructed a DFA 2.used goto statement to write a program. now it was very easy to model DFA using goto & i...
3
by: steve | last post by:
Is there anyway my AP can detect system goto Sleep, Hibernation mode, switch user and logoff?
13
by: Kartic | last post by:
Hi, Is it good practice using GOTO in .NET application? Please advice. Thanks, Kartic
77
by: M.B | last post by:
Guys, Need some of your opinion on an oft beaten track We have an option of using "goto" in C language, but most testbooks (even K&R) advice against use of it. My personal experience was that...
67
by: Rui Maciel | last post by:
I've been delving into finite state machines and at this time it seems that the best way to implement them is through an intense use of the goto statement. Yet, everyone plus their granmother is...
59
by: raashid bhatt | last post by:
why are GOTO's not used they just a simple JMP instructions what's bad about them
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.