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

一个函数里两个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

输出量

setjmp.h - longjmp() in c language

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

一个函数里两个setjmp

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541269.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux sublime nodejs,Ubuntu环境下sublime3 nodejs安装与插件配置

1.sudo add-apt-repository ppa:webupd8team/sublime-text-3回车&#xff0c;出现很多信息。但是我们看看图片最后字知道&#xff0c;这地方在等待我们确认是否添加这个仓库&#xff0c;按enter键继续&#xff0c;按crtlc取消。此时&#xff0c;按ENTER继续&#xff0c;建立信任…

李洪强iOS开发之FMDB线程安全的用法

// // ViewController.m // 04 - FMDB线程安全的用法 // // Created by 李洪强 on 2017/6/6. // Copyright © 2017年 李洪强. All rights reserved. // #import "ViewController.h" //导入头文件 #import "FMDB.h" interface ViewController () p…

SCHAR_MIN常数,C ++中的示例

C SCHAR_MIN宏常量 (C SCHAR_MIN macro constant) SCHAR_MIN constant is a macro constant which is defied in climits header, it is used to get the minimum value of a signed char object, it returns the minimum value that a signed char object can store, which i…

android分开两个线程做事,android开发教程之handle实现多线程和异步处理

这次浅谈一下Handler,为什么会出现Handler这个功能特性呢&#xff1f;首先&#xff0c;在之前的基本控件&#xff0c;基本都是在Activity的onCreate(Bundle savedInstanceState)方法中调用和处理的&#xff0c;但是&#xff0c;在有些情况&#xff0c;比如在网络上下载软件等一…

夏夜

儿时的夏夜毕竟是最有夏夜的味道。屋堂的煤油灯啪嗒的跳动&#xff0c;忽明忽暗&#xff0c;真怕它脆弱的明亮突然变黑暗。屋外弯月星稀&#xff0c;月光优雅的撒在平静的湖面上&#xff0c;清纯而又温和。水鸟在湖岸边慵懒的伸了伸脖子。正享受着夏夜的宁静和清凉。调皮的小孩…

Python operator.lt()函数与示例

operator.lt()函数 (operator.lt() Function) operator.lt() function is a library function of operator module, it is used to perform "less than operation" on two values and returns True if the first value is less than the second value, False, otherw…

android实现滑动切换图,Android:使用ViewPager实现左右滑动切换图片加点点

图片发自简书App1、引入android-support-v4.jar包&#xff0c;在主布局里加入< ?xml version"1.0" encoding"utf-8"?>< RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:tools"http://schemas.…

div的替代品

人们在标签使用中最常见到的错误之一就是随意将HTML5的<section>等价于<div>——具体地说&#xff0c;就是直接用作替代品(用于样式)。在XHTML或者HTML4中&#xff0c;我们常看到这样的代码&#xff1a; <!-- HTML 4-style code --> <div id"wrapper…

threadgroup_Java ThreadGroup list()方法与示例

threadgroupThreadGroup类的list()方法 (ThreadGroup Class list() method) list() method is available in java.lang package. list()方法在java.lang包中可用。 list() method is used to list or display information (like name, priority, thread group, etc.) to the st…

html的柱状图去除右边纵坐标,excel如何把次坐标轴逆序

excel2010设置水平坐标轴逆序类型,但垂直坐标轴刻设置水平坐标轴逆序且垂直坐标轴轴仍位于图表左侧的步骤是&#xff1a;打开带有图表的Excel工作表&#xff1b;在图表区域的水平轴标签位置双击鼠标左键&#xff0c;打开“设置坐标轴格式”&#xff1b;勾寻逆序类别”&#xff…

jhipster项目迁移websocket

2019独角兽企业重金招聘Python工程师标准>>> 1、 在项目目录下命令行安装 两个组件 bower install sockjs-client bower install stomp-websocket 2、在index.html 中加入组件js的引用 <script src"bower_components/sockjs-client/dist/sockjs.js">…

Java包hashCode()方法及示例

包类hashCode()方法 (Package Class hashCode() method) hashCode() method is available in java.lang package. hashCode()方法在java.lang包中可用。 hashCode() method is used to return the hashcode of the package calculated from the package name. hashCode()方法用…

html 图片上放置按钮,用CSS在图片上再加一个小按钮

很简单的&#xff0c;嗯&#xff0c;就是要做成这样的&#xff1a;用CSS&#xff0c;当然得用层了&#xff0c;就是在图片上再加一个层&#xff0c;用来放那个按钮&#xff0c;按钮又有两种方式可以放&#xff0c;一种是直接用图片img标签&#xff0c;一种是通过背景图片放上去…

html点击导航变色,点击导航后,当前导航的颜色变色

html>Documentnav ul {padding: 0;list-style: none;}nav ul li {text-decoration: none;width: 70px;line-height: 50px;text-align: center;float: left;background-color: #000;color: #fff;cursor: pointer;}.gray {background-color: rgba(0,0,0,0.6);}首页实战路径猿问…

Java扫描仪toString()方法及示例

扫描仪类toString()方法 (Scanner Class toString() method) toString() method is available in java.util package. toString()方法在java.util包中可用。 toString() method is used to string denotation of this Scanner and it contains information related to tracing.…

怎么将oracle的sql文件转换成mysql的sql文件

怎么将sql文件导入PowerDesigner中的方法(将oracle的sql文件转换成mysql的sql文件)呢&#xff1f; 怎么将xx.sql文件的数据库结构导入powerdesigner 的方法呢? 现讲下。 工具/原料 PowerDesigner软件&#xff0c;oracle数据库 方法/步骤 将要导入的库的所有表的表结构(不要表数…

ios html图片相对路径,iOS 下加载本地HTML/js/css/image 等路径问题

今天在项目中遇到一个问题&#xff1a;我将H5的文件拖入项目中&#xff0c;在webView上添加H5,运行时发现H5的样式与图片等都没屏幕快照 2016-07-06 11.33.22.png有了。经过多种测试后发现&#xff1a;是路径的问题。在ios项目下添加本地HTML/js/css/image 当拖入项目时有两种选…

nextfloat_Java Random nextFloat()方法与示例

nextfloat随机类nextFloat()方法 (Random Class nextFloat() method) nextFloat() method is available in java.util package. nextFloat()方法在java.util包中可用。 nextFloat() method is used to generate the next pseudo-random float value between the range 0.0 and …

mac自己定义tree命令

编辑文件: vim ~/.bash_profile 在文件末尾追加: alias tree"find . -print | sed -e s;[^/]*/;|____;g;s;____|; |;g" 应用配置: source ~/.bash_profile 转载于:https://www.cnblogs.com/gavanwanggw/p/6962533.html

Java Hashtable keySet()方法与示例

哈希表类keySet()方法 (Hashtable Class keySet() method) keySet() method is available in java.util package. keySet()方法在java.util包中可用。 keySet() method is used to return a set of keys to be viewed in a set in this Hashtable. keySet()方法用于返回要在此H…