📄 setjmp.c
字号:
/*
** A program to demonstrate the use of setjmp
*/
#include "trans.h"
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
/*
** The variable that stores setjmp's state information.
*/
jmp_buf restart;
int
main()
{
int value;
Trans *transaction;
/*
** Establish the point at which we want to resume execution
** after a call to longjmp.
*/
value = setjmp( restart );
/*
** Figure out what to do after a return from setjmp.
*/
switch( value ){
default:
/*
** longjmp was called -- fatal error
*/
fputs( "Fatal error.\n", stderr );
break;
case 1:
/*
** longjmp was called -- minor error
*/
fputs( "Invalid transaction.\n", stderr );
/* FALL THROUGH and continue processing */
case 0:
/*
** Original return from setjmp: perform normal
** processing.
*/
while( (transaction = get_trans()) != NULL )
process_trans( transaction );
}
/*
** Save data and exit the program
*/
write_data_to_file();
return value == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -