What is the difference between goto and longjmp() and setjmp()?
A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind should be avoided because it is not considered good programming practice to use such statements as goto and longjmp in your program. A goto statement simply bypasses code in your program and jumps to a predefined position. To use the goto statement, you give it a labeled position to jump to. This predefined position must be within the same function. You cannot implement gotos between functions. When your program calls setjmp(), the current state of your program is saved in a structure of type jmp_buf. Later, your program can call the longjmp() function to restore the program’s state as it was when you called setjmp().Unlike the goto statement, the longjmp() and setjmp() functions do not need to be implemented in the same function. However, there is a major drawback to using these functions: your program, when restored to its previously saved state, will lose its references to any dynamically allocated memory between the longjmp() and the setjmp(). This means you will waste memory for every malloc() or calloc() you have implemented between your longjmp() and setjmp(), and your program will be horribly inefficient. It is highly recommended that you avoid using functions such as longjmp() and setjmp() because they, like the goto statement, are quite often an indication of poor programming practice.
Showing Answers 1 - 1 of 1 Answers
- What is the difference between potential and voltage?
- What is the difference between earth and neutral ?
- What is difference between win XP and win 7
- QTP launch application methods
- Citrix vdi and citrix xendesktop
- Xenapp 6.0 and xenapp 6.5
- What is the difference body & neutral earthing ?
- What are the basic difference between re-insurance and insurance claim handling?
- Business rule & business validation
- Power system
- C program to compare two text files
- What is the difference in C and Java ?
- Launch any application methods in QTP
- Microstrategy differences
- What is the difference between a Java developer and Java designer?
- Cash management service
- Is there any difference between web application testing and sharepoint application testing.
- Difference between Informatica 8.1 and 8.6 in briefly
- Worksoft certify