goto

how does url within function body get compiled

折月煮酒 提交于 2019-11-26 17:18:08
问题 I just pasted a url to my code, and forgot to comment it, but I was surprised to see MSVC++ compiled it successfully. My code is like this, void my_function() { http://www.google.co.in/ } How come this gets compiled by MSVC++? 回答1: Actually, http followed by a colon is treated as a label by C++, which you can use in goto statements (like goto http; ), and the rest (i.e //www.google.co.in ) is treated as single line comment. That's why it gets compiled. See more, void your_function() { http:/

Use GOTO or not? [closed]

旧城冷巷雨未停 提交于 2019-11-26 15:18:07
Currently I am working on a project where goto statements are heavely used. The main purpose of goto statements is to have one cleanup section in a routine rather than multiple return statements. Like below: BOOL foo() { BOOL bRetVal = FALSE; int *p = NULL; p = new int; if (p == NULL) { cout<<" OOM \n"; goto Exit; } // Lot of code... Exit: if(p) { delete p; p = NULL; } return bRetVal; } This makes it much easier as we can track our clean up code at one section in code, that is, after the Exit label. However, I have read many places it's bad practice to have goto statements. Currently I am

windows batch file with goto command not working

本秂侑毒 提交于 2019-11-26 14:25:25
问题 I have a problem with GOTO command and affiliated labels. Facts: Given a bunch of files from a folder (they are log errors) I need to open them and check if they contain a specific string. If yes then eliminate some characters (all the chars after the last appearance of "_", including itself) from the file names and do other operations. For cutting off the chars I'm using GOTO command in a loop manner as I found it described here: http://www.robvanderwoude.com/battech_while_loops.php The

How can I use goto in Javascript?

与世无争的帅哥 提交于 2019-11-26 14:16:43
I have some code that I absolutely must implement using goto . For example, I want to write a program like this: start: alert("RINSE"); alert("LATHER"); repeat: goto start Is there a way to do that in Javascript? Peter Olson Absolutely! There is a project called Summer of Goto that allows you use JavaScript at its fullest potential and will revolutionize the way you can write your code. This JavaScript preprocessing tool allows you to create a label and then goto it using this syntax: [lbl] <label-name> goto <label-name> For example, the example in the question can be written as follows: [lbl]

Alternative to a goto statement in Java

我是研究僧i 提交于 2019-11-26 11:44:58
What is an alternative function for the goto keyword in Java? Since Java does not have a goto. Padmarag You could use a labeled BREAK statement: search: for (i = 0; i < arrayOfInts.length; i++) { for (j = 0; j < arrayOfInts[i].length; j++) { if (arrayOfInts[i][j] == searchfor) { foundIt = true; break search; } } } However, in properly designed code, you shouldn't need GOTO functionality. Stephen C There isn't any direct equivalent to the goto concept in Java. There are a few constructs that allow you to do some of the things you can do with a classic goto . The break and continue statements

Is there a “goto” statement in bash?

戏子无情 提交于 2019-11-26 11:44:16
Is there a "goto" statement in bash ? I know It is considered bad practice, but I need specifically "goto". No, there is not; see §3.2.4 "Compound Commands" in the Bash Reference Manual for information about the control structures that do exist. In particular, note the mention of break and continue , which aren't as flexible as goto , but are more flexible in Bash than in some languages, and may help you achieve what you want. (Whatever it is that you want . . .) If you are using it to skip part of a large script for debugging (see Karl Nicoll's comment), then if false could be a good option

c99 goto past initialization

十年热恋 提交于 2019-11-26 11:13:15
问题 While debugging a crash, I came across this issue in some code: int func() { char *p1 = malloc(...); if (p1 == NULL) goto err_exit; char *p2 = malloc(...); if (p2 == NULL) goto err_exit; ... err_exit: free(p2); free(p1); return -1; } The problem occurs when the first malloc fails. Because we jump across the initialization of p2 , it contains random data and the call to free(p2) can crash. I would expect/hope that this would be treated the same way as in C++ where the compiler does not allow a

Is it ever advantageous to use &#39;goto&#39; in a language that supports loops and functions? If so, why?

这一生的挚爱 提交于 2019-11-26 11:00:39
I've long been under the impression that goto should never be used if possible. While perusing libavcodec (which is written in C) the other day, I noticed multiple uses of it. Is it ever advantageous to use goto in a language that supports loops and functions? If so, why? Chris Gillum There are a few reasons for using the "goto" statement that I'm aware of (some have spoken to this already): Cleanly exiting a function Often in a function, you may allocate resources and need to exit in multiple places. Programmers can simplify their code by putting the resource cleanup code at the end of the

Is using a &#39;goto&#39; statement bad?

。_饼干妹妹 提交于 2019-11-26 10:34:38
After doing some reseach on how to break through a secondary loop while (true) { // Main Loop for (int I = 0; I < 15; I++) { // Secondary loop // Do Something break; // Break main loop? } } most people recommended to call the 'goto' function Looking as the following example: while (true) { // Main Loop for (int I = 0; I < 15; I++) { // Secondary Loop // Do Something goto ContinueOn; // Breaks the main loop } } ContinueOn: However; I have often heard that the 'goto' statement is bad practice. The picture below is perfectly illustrating my point: So How bad is the goto statement really, and why?

Is GOTO in PHP evil? [closed]

北城余情 提交于 2019-11-26 07:31:17
问题 I recently found out that PHP 5.3 supports new language construct called GOTO . Everybody knows what it does. However, it\'s not exactly the traditional GOTO , it\'s just a jump label. I\'m interesting in knowing whether this GOTO is evil and implies bad code? 回答1: 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. 回答2: I can