Files
oldlinux-files/study/Ref-docs/C/setjmp.html
2024-02-19 00:25:23 -05:00

91 lines
3.7 KiB
HTML

<HTML><HEAD><TITLE>&lt;setjmp.h&gt;</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
<H1><A NAME="&lt;setjmp.h&gt;"><CODE>&lt;setjmp.h&gt;</CODE></A></H1><HR>
<P><CODE>
typedef <I>a-type</I> <A HREF="#jmp_buf"><B>jmp_buf</B></A>;<BR>
void <A HREF="#longjmp"><B>longjmp</B></A>(jmp_buf env,
int val);<BR>
#define <A HREF="#setjmp"><B>setjmp</B></A>(jmp_buf env)
<I>&lt;int rvalue&gt;</I>
</CODE></P>
<P>Include the standard header <B><CODE>&lt;setjmp.h&gt;</CODE></B>
to perform control transfers that bypass
the normal function call and return protocol.</P>
<H2><A NAME="jmp_buf"><CODE>jmp_buf</CODE></A></H2>
<P><CODE>
typedef <I>a-type</I> <B>jmp_buf</B>;
</CODE></P>
<P>The type is the array type <CODE><I>a-type</I></CODE> of an object that
you declare to hold the context information stored by
<A HREF="#setjmp"><CODE>setjmp</CODE></A> and accessed by
<A HREF="#longjmp"><CODE>longjmp</CODE></A>.</P>
<H2><A NAME="longjmp"><CODE>longjmp</CODE></A></H2>
<P><CODE>
void <B>longjmp</B>(jmp_buf env, int val);
</CODE></P>
<P>The function causes a second return from the execution of
<A HREF="#setjmp"><CODE>setjmp</CODE></A>
that stored the current context value in <CODE>env</CODE>.
If <CODE>val</CODE> is nonzero, the return value is <CODE>val</CODE>;
otherwise, it is 1.</P>
<P>The function that was active when
<A HREF="#setjmp"><CODE>setjmp</CODE></A> stored the current
context value must not have returned control to its caller. An object
with dynamic duration that does not have a <I>volatile</I> type and
whose stored value has changed since the current context value was stored
will have a stored value that is indeterminate.</P>
<H2><A NAME="setjmp"><CODE>setjmp</CODE></A></H2>
<P><CODE>
#define <B>setjmp</B>(jmp_buf env) <I>&lt;int rvalue&gt;</I>
</CODE></P>
<P>The macro stores the current context value in the array
designated by <CODE>env</CODE> and returns zero. A later call to
<A HREF="#longjmp"><CODE>longjmp</CODE></A>
that accesses the same context value causes
<CODE>setjmp</CODE> to again return, this time with a nonzero value.
You can use the macro <CODE>setjmp</CODE> only in an expression that:</P>
<UL>
<LI>has no operators
<LI>has only the unary operator <CODE>!</CODE>
<LI>has one of the relational or equality operators (<CODE>==</CODE>,
<CODE>!=</CODE>, <CODE>&lt;</CODE>, <CODE>&lt;=</CODE>,
<CODE>&gt;</CODE>, or <CODE>&gt;=</CODE>) with the other
operand an integer constant expression
</UL>
<P>You can write such an expression only as the <I>expression</I>
part of a
<A HREF="function.html#Do Statement" tppabs="http://ccs.ucsd.edu/c/function.html#Do Statement"><I>do</I></A>,
<A HREF="function.html#Expression Statement" tppabs="http://ccs.ucsd.edu/c/function.html#Expression Statement"><I>expression</I></A>,
<A HREF="function.html#For Statement" tppabs="http://ccs.ucsd.edu/c/function.html#For Statement"><I>for</I></A>,
<A HREF="function.html#If Statement" tppabs="http://ccs.ucsd.edu/c/function.html#If Statement"><I>if</I></A>,
<A HREF="function.html#If-Else Statement" tppabs="http://ccs.ucsd.edu/c/function.html#If-Else Statement"><I>if-else</I></A>,
<A HREF="function.html#Switch Statement" tppabs="http://ccs.ucsd.edu/c/function.html#Switch Statement"><I>switch,</I></A>, or
<A HREF="function.html#While Statement" tppabs="http://ccs.ucsd.edu/c/function.html#While Statement"><I>while</I></A> statement.</P>
<HR>
<P>See also the
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
<P><I>
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> &#169; 1989-1996
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
</BODY></HTML>