setjmp.c

来自「sdcc是为51等小型嵌入式cpu设计的c语言编译器支持数种不同类型的cpu」· C语言 代码 · 共 55 行

C
55
字号
/** setjmp/longjmp tests.*/#include <testfwk.h>#include <setjmp.h>unsigned int global_int = 0;unsigned int *gpInt;#if defined(SDCC_mcs51)#include <8052.h>void T2_isr (void) interrupt 5 //no using{  //do not clear flag TF2 so it keeps interrupting !  (*gpInt)++;}#endif#if defined(SDCC_mcs51) || defined(PORT_HOST)void try_fun(jmp_buf catch, int except){  longjmp(catch, except);}#endifvoidtestJmp(void){#if defined(SDCC_mcs51) || defined(PORT_HOST)  jmp_buf catch;  int exception;#if defined(SDCC_mcs51)  gpInt = &global_int;  //enable the interrupt and set it's flag to generate some heavy stack usage  ET2 = 1;  EA = 1;  TF2 = 1;#endif  exception = setjmp(catch);  if (exception == 0)  {  	try_fun(catch, 1);  	//should not get here!  	ASSERT(0);  }  ASSERT(exception == 1);#endif}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?