Hello,
Does anyone know what the following g++ compiler error message means:
error: jump to case label
I get this error when switching two case labels together with their bodies.
I have no setjmp/longjmp or gotos in my program.
Thanks,
Neil 11 17265
Neil Zanella wrote: I get this error when switching two case labels together with their bodies.
Explain that further or better yet post the offending code.
On Fri, 02 Apr 2004 15:09:00 -0800, Neil Zanella wrote: Hello,
Does anyone know what the following g++ compiler error message means:
error: jump to case label
I get this error when switching two case labels together with their bodies. I have no setjmp/longjmp or gotos in my program.
Perhaps the problem is "jump to case label croses initialization"?
The following is not allowed:
switch (a)
{
case 1:
int a = 6;
//stuff
break;
case 2:
//stuff
break;
}
The following is allowed:
switch (a)
{
case 1:
{
int a = 6;
//stuff
}
break;
case 2:
//stuff
break;
}
James
On Fri, 02 Apr 2004 15:09:00 -0800, Neil Zanella wrote: Hello,
Does anyone know what the following g++ compiler error message means:
error: jump to case label
I get this error when switching two case labels together with their bodies. I have no setjmp/longjmp or gotos in my program.
Perhaps the problem is "jump to case label croses initialization"?
The following is not allowed:
switch (a)
{
case 1:
int a = 6;
//stuff
break;
case 2:
//stuff
break;
}
The following is allowed:
switch (a)
{
case 1:
{
int a = 6;
//stuff
}
break;
case 2:
//stuff
break;
}
James
Bill Seurer <se****@us.ibm.com> wrote in message news:<c4***********@news.rchland.ibm.com>... Neil Zanella wrote:
I get this error when switching two case labels together with their bodies.
Explain that further or better yet post the offending code.
Sure I will. Here is the code. Uncommenting the lines for case 1 produces
the compiler error message. Furthermore, out of curiosity, as an unrelated
matter, I am quite interested in knowing how come the program starts looping
when some large number is entered.
Thanks,
Neil
#include <iostream>
int main() {
unsigned int x; do {
std::cout << "Please enter an integer: " << std::flush;
std::cin >> x;
switch (x) {
case 0:
std::cout << "Hello!" << std::endl;
break;
default:
unsigned int y = ++x;
std::cout << "You could have entered " << y;
std::cout << ". Why didn't you?" << std::endl;
break;
//case 1:
// std::cout << "What??? You entered one?" << std::endl;
// break;
}
} while (x != 0);
}
Bill Seurer <se****@us.ibm.com> wrote in message news:<c4***********@news.rchland.ibm.com>... Neil Zanella wrote:
I get this error when switching two case labels together with their bodies.
Explain that further or better yet post the offending code.
Sure I will. Here is the code. Uncommenting the lines for case 1 produces
the compiler error message. Furthermore, out of curiosity, as an unrelated
matter, I am quite interested in knowing how come the program starts looping
when some large number is entered.
Thanks,
Neil
#include <iostream>
int main() {
unsigned int x; do {
std::cout << "Please enter an integer: " << std::flush;
std::cin >> x;
switch (x) {
case 0:
std::cout << "Hello!" << std::endl;
break;
default:
unsigned int y = ++x;
std::cout << "You could have entered " << y;
std::cout << ". Why didn't you?" << std::endl;
break;
//case 1:
// std::cout << "What??? You entered one?" << std::endl;
// break;
}
} while (x != 0);
}
Neil Zanella wrote: Sure I will. Here is the code. Uncommenting the lines for case 1 produces the compiler error message.
Try moving them before the 'default'
Furthermore, out of curiosity, as an unrelated matter, I am quite interested in knowing how come the program starts looping when some large number is entered.
cin.fail() is set and all subsequent ">>" operations are ignored,
with x unmodified every time. Hence, if x happened to be non-zero,
the loop iterates infinitely. Thanks,
Neil
#include <iostream>
int main() { unsigned int x; do { std::cout << "Please enter an integer: " << std::flush; std::cin >> x; switch (x) { case 0: std::cout << "Hello!" << std::endl; break; default: unsigned int y = ++x; std::cout << "You could have entered " << y; std::cout << ". Why didn't you?" << std::endl; break; //case 1: // std::cout << "What??? You entered one?" << std::endl; // break; } } while (x != 0); }
HTH,
- J.
Neil Zanella wrote: Sure I will. Here is the code. Uncommenting the lines for case 1 produces the compiler error message.
Try moving them before the 'default'
Furthermore, out of curiosity, as an unrelated matter, I am quite interested in knowing how come the program starts looping when some large number is entered.
cin.fail() is set and all subsequent ">>" operations are ignored,
with x unmodified every time. Hence, if x happened to be non-zero,
the loop iterates infinitely. Thanks,
Neil
#include <iostream>
int main() { unsigned int x; do { std::cout << "Please enter an integer: " << std::flush; std::cin >> x; switch (x) { case 0: std::cout << "Hello!" << std::endl; break; default: unsigned int y = ++x; std::cout << "You could have entered " << y; std::cout << ". Why didn't you?" << std::endl; break; //case 1: // std::cout << "What??? You entered one?" << std::endl; // break; } } while (x != 0); }
HTH,
- J.
Jacek Dziedzic <ja*************@janowo.net> wrote in message: Try moving them before the 'default'
Thank you for your reply...
I know that works but that doens't really explain the nature of the problem.
Regards,
Neil #include <iostream>
int main() { unsigned int x; do { std::cout << "Please enter an integer: " << std::flush; std::cin >> x; switch (x) { case 0: std::cout << "Hello!" << std::endl; break; default: unsigned int y = ++x; std::cout << "You could have entered " << y; std::cout << ". Why didn't you?" << std::endl; break; //case 1: // std::cout << "What??? You entered one?" << std::endl; // break; } } while (x != 0); }
HTH, - J.
Jacek Dziedzic <ja*************@janowo.net> wrote in message: Try moving them before the 'default'
Thank you for your reply...
I know that works but that doens't really explain the nature of the problem.
Regards,
Neil #include <iostream>
int main() { unsigned int x; do { std::cout << "Please enter an integer: " << std::flush; std::cin >> x; switch (x) { case 0: std::cout << "Hello!" << std::endl; break; default: unsigned int y = ++x; std::cout << "You could have entered " << y; std::cout << ". Why didn't you?" << std::endl; break; //case 1: // std::cout << "What??? You entered one?" << std::endl; // break; } } while (x != 0); }
HTH, - J.
Neil Zanella wrote: Jacek Dziedzic <ja*************@janowo.net> wrote in message:
Try moving them before the 'default'
Thank you for your reply... I know that works but that doens't really explain the nature of the problem.
Please don't top-post. #include <iostream>
int main() { unsigned int x; do { std::cout << "Please enter an integer: " << std::flush; std::cin >> x; switch (x) { case 0: std::cout << "Hello!" << std::endl; break; default: unsigned int y = ++x; std::cout << "You could have entered " << y; std::cout << ". Why didn't you?" << std::endl; break; //case 1: // std::cout << "What??? You entered one?" << std::endl; // break; } } while (x != 0); }
James Gregory is right. The 'jump' in the error message is the computed
goto effected by the switch statement. When x = 1, the switch acts like
this:
goto case_label_1;
// ...
unsigned int y = ++ x;
// ...
case_label_1:
// here y is uninitialized
The problem is that the initialization of y is skipped when x == 1.
When the "case 1:" label is reached, stack space has been allocated for
y but its value has not been initialized. This is not allowed.
The general way round this situation is to make the scope of y smaller
by adding braces:
switch (x)
{
default:
unsigned z; // this is OK since z is uninitialized
{
unsigned y = x + 1;
// ...
}
case 1:
z = 2;
// ...
// cannot refer to y here so no problem with y's initialization
}
--
Regards,
Buster.
Neil Zanella wrote: Jacek Dziedzic <ja*************@janowo.net> wrote in message:
Try moving them before the 'default'
Thank you for your reply... I know that works but that doens't really explain the nature of the problem.
Please don't top-post. #include <iostream>
int main() { unsigned int x; do { std::cout << "Please enter an integer: " << std::flush; std::cin >> x; switch (x) { case 0: std::cout << "Hello!" << std::endl; break; default: unsigned int y = ++x; std::cout << "You could have entered " << y; std::cout << ". Why didn't you?" << std::endl; break; //case 1: // std::cout << "What??? You entered one?" << std::endl; // break; } } while (x != 0); }
James Gregory is right. The 'jump' in the error message is the computed
goto effected by the switch statement. When x = 1, the switch acts like
this:
goto case_label_1;
// ...
unsigned int y = ++ x;
// ...
case_label_1:
// here y is uninitialized
The problem is that the initialization of y is skipped when x == 1.
When the "case 1:" label is reached, stack space has been allocated for
y but its value has not been initialized. This is not allowed.
The general way round this situation is to make the scope of y smaller
by adding braces:
switch (x)
{
default:
unsigned z; // this is OK since z is uninitialized
{
unsigned y = x + 1;
// ...
}
case 1:
z = 2;
// ...
// cannot refer to y here so no problem with y's initialization
}
--
Regards,
Buster. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andreas |
last post by:
Hi,
can someone tell me how i do create a jump table in c or c++ ?
I tried this:
void f()
{
void *jump_table =
{
label1,
|
by: Neil Zanella |
last post by:
Hello,
Does anyone know what the following g++ compiler error message means:
error: jump to case label
I get this error when switching two case labels together with their bodies.
I have no...
|
by: Steve Hoyer |
last post by:
I am trying to deploy my first asp.net app to our webserver (2K server,
IIS 5)
My start page comes up and you can get to the subsequent pages that are
tied into our sql server (2K). Each page...
|
by: Anthony England |
last post by:
I am considering general error handling routines and have written a sample
function to look up an ID in a table. The function returns True if it can
find the ID and create a recordset based on...
|
by: dc15 |
last post by:
I am trying to write an application, taking input from various text
boxes and appending it to a text file.... it was working, then I had to
create various sub procedures to reflect limits set in...
| |
by: sam_cit |
last post by:
Hi Everyone,
I wanted to know as to how a switch case like the following one is
converted into a jump table by the compiler, assuming that it does,
switch(i)
{
case 4 : {
...
printf("4");
|
by: AJ32 |
last post by:
I have written a Dev-C++ program that needs to read and write to and from files, also it needs to use the goto function to jump to different parts of the program, after I finished writting the...
|
by: Franz Hose |
last post by:
the following program, when compiled with gcc and '-std=c99', gcc says
test.c:6: error: jump into scope of identifier with
variably modified type
that is, it does not even compile.
...
|
by: KRISHNA PRAVI |
last post by:
the error is "runtime error object expected" here is the code.......................................................................................
<script language="javascript"...
|
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...
|
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,...
| |
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |