Is it possible to store the address of a label in a variable and use goto to jump to it?

The C and C++ standards do not support this feature. However, the GNU Compiler Collection (GCC) includes a non-standard extension for doing this, as described in the Labels as Values section of the Using the GNU Compiler Collection manual. Essentially, they have added a special unary operator && that reports the address of the label … Read more

Is there a goto statement in Java?

James Gosling created the original JVM with support of goto statements, but then he removed this feature as needless. The main reason goto is unnecessary is that usually it can be replaced with more readable statements (like break/continue) or by extracting a piece of code into a method. Source: James Gosling, Q&A session

Address of labels (MSVC)

The only way of doing this in MSVC is by using inline assembly (which basically buggers you for x64): int _tmain(int argc, _TCHAR* argv[]) { case_1: void* p; __asm{ mov [p],offset case_1 } printf(“0x%p\n”,p); return 0; } If you plan on doing something like this, then the best way would be to write the whole … Read more

How to use goto statement correctly

As already pointed out by all the answers goto – a reserved word in Java and is not used in the language. restart: is called an identifier followed by a colon. Here are a few things you need to take care of if you wish to achieve similar behavior – outer: // Should be placed … Read more

When implementing an infinite loop, is there a difference in using while(1) vs for(;;) vs goto (in C)?

They are equivalent, even if you turn the optimizer off. Example: #include <stdio.h> extern void f(void) { while(1) { putchar(‘ ‘); } } extern void g(void) { for(;;){ putchar(‘ ‘); } } extern void h(void) { z: putchar(‘ ‘); goto z; } Compile with gcc -O0 gives equivalent assembly for all 3 functions: f: ; … Read more

To GOTO or not to GOTO? [closed]

I am not sure what do you mean by clean up code but in C++ there is a concept called “resource acquisition is initialization” and it should be the responsibility of your destructors to clean up stuff. (Note that in C# and Java, this is usually solved by try/finally) For more info check out this … Read more

c99 goto past initialization

You can ask gcc to warn you when you jump over a variable definition by using -Wjump-misses-init and then you can use -Werror (or, more precisely, -Werror=jump-misses-init) to force the users to deal with it. This warning is included in -Wc++-compat so the gcc developers are aware that the code behaves differently in C versus … Read more

Is GOTO in PHP evil? [closed]

Unless you are programming in assembler, GOTO should always be treated the same way as the life vest of the airplanes: it is good to have them available, but if you need to use them it means that you are in big trouble.

Scanf won’t execute for second time

Caution: fflush(stdin); may be undefined behavior. Read: Why fflush(stdin) is wrong? int fflush(FILE *ostream); The ostream points to an output stream or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to … Read more