一个函数里两个setjmp

We can call this function as an advance version of goto statement but with more dynamic range. The longjump() function allows us to pass parameters to know that the control has been jumped or not.

我们可以将此函数称为goto语句的高级版本,但具有更大的动态范围。 longjump()函数使我们可以传递参数来知道控件是否已跳转。

So how to use this is the question. First thing is to decide point from where you want to jump and then decide to where you want to jump.

因此,如何使用此问题。 第一件事是确定要从哪里跳转的点,然后再确定要跳转的位置。

Before setting these point just make a jum_buf object. Now rest is a cake walk. In this example, I have put the point from where we want to jump inside a function called func by calling the function longjmp(a, 1) with two parameters as the jum_buf object and 1 will be return at the setjump call.

在设置这些点之前,只需创建一个jum_buf对象。 现在休息是轻轻松松。 在此示例中,我通过调用带有两个参数的longjmp(a,1)函数作为jum_buf对象,将要从其中跳转到函数func的位置,在setjump调用中将返回1。

Call the function setjmp() at the point to where you want to jump. The Second parameter from the longjump will be stored in z. This z can be then checked for loops or maybe something else.

在要跳转的位置调用函数setjmp() 。 longjump中的第二个参数将存储在z中 。 然后可以检查此z的循环或其他内容。

setjmp.h- longjmp()函数在C中的示例 (setjmp.h- longjmp() function Example in C)

</ s> </ s> </ s>

#include <stdio.h>
#include <setjmp.h>
//defining the type of the variable
static jmp_buf a;
void func(void)
{//message for user
printf("Function starts here..\n");
//calling function
longjmp(a, 1);
//message for user
printf("Function ends here..\n");
}
int main()
{int z;
//message for user
printf("Main starts here..\n");
//setting current value in z
z = setjmp(a);
//condition to display message
if (z != 0)
{//message for user
printf("longjmp function called\n");
return 0;
}
func();
//message for user
printf("Main ends here..\n");
return 0;
}

Output

输出量

翻译自: https://www.includehelp.com/c-programs/longjmp-function-of-setjmp-h-in-c.aspx

一个函数里两个setjmp

一个函数里两个setjmp_C语言中setjmp.h的longjmp()函数相关推荐

  1. fwrite函数的用法示例_C语言中的fwrite()函数(带有示例)

    fwrite函数的用法示例 C中的fwrite()函数 (fwrite() function in C) Prototype: 原型: size_t fwrite(void *buffer, size ...

  2. exit在c语言里的作用,C语言中exit函数的使用

    exit() 结束当前进程/当前程序/,在整个程序中,只要调用 exit ,就结束 return() 是当前函数返回,当然如果是在主函数main, 自然也就结束当前进程了,如果不是,那就是退回上一层调 ...

  3. 关于C语言中的malloc和free函数的用法

    一.malloc()和free()的基本概念以及基本用法: 1.函数原型及说明: void *malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针 ...

  4. C语言 SLEEP函数不起作用,C语言中的sleep() 函数 sleep函数的具体用法

    导航:网站首页 > C语言中的sleep() 函数 sleep函数的具体用法 C语言中的sleep() 函数 sleep函数的具体用法 相关问题: 匿名网友: 关于sleep()函数在windo ...

  5. c语言 strcpy原型,浅谈C语言中strcpy,strcmp,strlen,strcat函数原型

    实例如下: //strcat(dest,src)把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0' char *strcat(char * strDest, cons ...

  6. c语言中math的库函数,C语言中math.h库中的常用函数

    C语言中math.h库中的常用函数 int abs(int i) 返回整型参数i的绝对值 double cabs(struct complex znum) 返回复数znum的绝对值 double fa ...

  7. putc函数_C语言中的putc()函数与示例

    putc函数 C语言中的putc()函数 (putc() function in C) The putc() function is defined in the <stdio.h> he ...

  8. fopen函数的用法示例_使用示例的C语言中的fopen()函数

    fopen函数的用法示例 C语言中的fopen()函数 (fopen() function in C) Prototype: 原型: FILE *fopen(const char* filename, ...

  9. C语言中的malloc与free函数

    C语言中的malloc与free函数 malloc函数的作用是在堆中开辟一块指定大小的空间.如果开辟成功,返回空间首个字节地址,失败则返回NULL. free函数能够释放在堆中开辟的内存空间,传入一个 ...

最新文章

  1. mysql group by 区间_SQL按区间进行group by
  2. Android4.0源码Launcher启动流程分析【android源码Launcher系列一】
  3. tf.truncated_normal的用法
  4. php self 内存,php导致内存溢出
  5. jq之slideDown() stop()
  6. Parameter '**' not found. Available parameters are [0, 1, param1, param2]解决办法
  7. 设计师必收藏!!!让你灵感迸发的配色网站
  8. 微信分享踩坑:config:invalid signature错误的解决方法
  9. delphi延时 4种方法
  10. java认证考试(java认证考试报名)
  11. python将多个txt内容合并_python合并多个txt文件成为一个文件
  12. 稳压二极管的原理和伏安特性
  13. DataSheet IFI9486
  14. zmud之自动解谜:不用数据库实现自动解谜的原理。
  15. 抓取百度搜狗相关搜索、筛选文本相似度最高的相关搜索(PHP)
  16. [GIS教程] 7 空间数据查询与空间度量
  17. 【T+】畅捷通T+登录的时候,提示仅支持以手机号或邮箱登录。
  18. STM32MP157C-DK2->Develop on Arm® Cortex®-A7之 C语言开发uart例程
  19. 五金切断模具结构和设计注意事项
  20. C++中引用,指针,指针的引用,指针的指针

热门文章

  1. php访问网页post获取源码,第一次抓别人网站数据,用postman直接请求可以获取到返回数据,通过代码的方式就一直报错,php...
  2. 奥鹏东师计算机应用基础18,免费在线作业答案奥鹏东师计算机应用基础15秋在线作业1试卷及答案(1)...
  3. sqli-lab——Writeup21~38(各种过滤绕过WAF和)
  4. 切割照片php上传,php下ajax的文件切割上传
  5. sql oracle 递归查询语句,Oracle使用SQL语句进行递归查询
  6. css span 右端对齐_CSS标准文档流
  7. eplan单线原理图多线原理图_EPLAN-黑盒-2
  8. 百度MIP页规范详解 —— canonical标签
  9. snort的详细配置
  10. 服务器电流源泉ups电源的三大形式