goto

'goto *foo' where foo is not a pointer. What is this?

那年仲夏 提交于 2019-12-04 15:27:58
问题 I was playing around with labels as values and ended up with this code. int foo = 0; goto *foo; My C/C++ experience tells me *foo means dereference foo and that this won't compile because foo isn't a pointer. But it does compile. What does this actually do? gcc (Ubuntu 4.9.2-0ubuntu1~12.04) 4.9.2 , if important. 回答1: This is a known bug in gcc. gcc has a documented extension that permits a statement of the form goto *ptr; where ptr can be any expression of type void* . As part of this

How GOTO statement in Groovy?

主宰稳场 提交于 2019-12-04 13:06:15
I saw this nice blog post about a Scala continuations that 'emulates' a GOTO statement in the Scala language. (read more about Continuations here ) I would like to have the same in the programming language Groovy. I think it's possible within a Groovy compiler phase transformation . I'm working on an Domain-Specific Language (DSL), and preferred embedded in Groovy. I would like to have the GOTO statement, because the DSL is an unstructured language (and is generated from workflow diagrams). I need a 'labeled' goto statement, not to line numbers. The DSL is a language for workflow definitions,

How to use goto to break a nested loop

风流意气都作罢 提交于 2019-12-04 10:51:05
How can I use a "goto" statement to break out of a loop for(i = 0; (i < 9); i++) { for(j = 0; j < 9; j++) { //cout << " " << Matrix[i][j]; //cout << "i: " << i << endl; if(Matrix[i][j] == 0) { //temp = 10; [goto] ; //break; } } } I wanted to keep the values at which i and j were when I left the nested for loop. How can I use a goto statement for that? Like this: int i,j; for(i = 0; i < 9; i++) { for(j = 0; j < 9; j++) { //cout << " " << Matrix[i][j]; //cout << "i: " << i << endl; if(Matrix[i][j] == 0) { //temp = 10; goto end; //break; } } } end: cout << i << " " << j << endl; Just as you use

C++ if condition not checked after goto

和自甴很熟 提交于 2019-12-04 07:11:54
问题 I'm working on a simplish game (this isn't the whole code, just the bit that I'm having issues with) and I've run into this issue; After the condition is furfilled, it goes back to the start and it offers me to reenter the string, however, whatever I enter, I just get 'Not Valid' . Does anyone know why? I'm using the GNU C++ Compiler . #include <iostream> #include <string> using namespace std; int main() { string command; mainscreen: cout << "blab"; getlinething: cin.ignore(); getline(cin,

Skip variable declaration using goto?

末鹿安然 提交于 2019-12-04 05:53:05
I am reading C Programming - A Modern Approach by K.N.King to learn the C programming language and it was noted that goto statements must not skip variable-length array declarations. But now the question is: Why are goto jumps allowed to skip fixed-length array declarations and ordinary declarations? And more precisely, what is the behavior of examples like these, according to the C99 standard? When I tested these cases it seemed like the declarations were actually not jumped over, but is that correct? Are the variables whose declarations might have been jumped over safe to use? 1. goto later;

Is it okay to use “go to” from a catch statement

本秂侑毒 提交于 2019-12-04 03:21:32
问题 Everything I have ever been told is that go to's are evil and stay away from them, but I think they may help me here (?). I would like to provide the user an option to restart the application when an exception is caught and am having a bit of trouble wrapping my head around what to do... My application will be monitored by another process, but there are some exceptions where I want to the user to be able to decide what to do without returning control to the calling process. Is something like

effect of goto on C++ compiler optimization

 ̄綄美尐妖づ 提交于 2019-12-03 22:27:13
What are the performance benefits or penalties of using goto with a modern C++ compiler? I am writing a C++ code generator and use of goto will make it easier to write. No one will touch the resulting C++ files so don't get all "goto is bad" on me . As a benefit, they save the use of temporary variables. I was wondering, from a purely compiler optimization perspective, the result that goto has on the compiler's optimizer? Does it make code faster , slower , or generally no change in performance compared to using temporaries / flags. The part of a compiler that would be affected works with a

C: Nested Ifs or Gotos

拜拜、爱过 提交于 2019-12-03 12:23:24
What is the best way to manage resources for a C program. Should I use a nested if structure or should I use goto statements? I am aware there is a lot of taboo about goto statements. However, I think it is justified for local resource clean up. I have supplied two samples. One compares a nested if structure and another uses goto statements. I personally find the goto statements make the code easier to read. For those who might argue that the nested if prompt better structure, imagine if the datatype was something other than a char*, like a Windows handle. I feel that the nested if structure

Continue Considered Harmful? [closed]

前提是你 提交于 2019-12-03 11:52:58
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Should developers avoid using continue in C# or its equivalent in other languages to force the next iteration of a loop? Would

C/C++: goto into the for loop

走远了吗. 提交于 2019-12-03 11:21:33
I have a bit unusual situation - I want to use goto statement to jump into the loop, not to jump out from it. There are strong reasons to do so - this code must be part of some function which makes some calculations after the first call, returns with request for new data and needs one more call to continue. Function pointers (obvious solution) can't be used because we need interoperability with code which does not support function pointers. I want to know whether code below is safe, i.e. it will be correctly compiled by all standard-compliant C/C++ compilers (we need both C and C++). function