一個函數里兩個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.pswp.cn/news/541269.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541269.shtml
英文地址,請注明出處:http://en.pswp.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…