environment in which the call to @code{setjmp} appears in an object of
type @code{jmp_buf}. Execution of the program continues normally after
the call to @code{setjmp}, but if a exit is later made to this return
-point by calling @code{longjmp} with the corresponding @code{jmp_buf}
+point by calling @code{longjmp} with the corresponding @w{@code{jmp_buf}}
object, control is transferred back to the point where @code{setjmp} was
called. The return value from @code{setjmp} is used to distinguish
between an ordinary return and a return made by a call to
@code{longjmp}, so calls to @code{setjmp} usually appear in an @samp{if}
statement.
-Here is how the example program described above might be set up:
+Here is how the example program described above might be set up:
-@example
+@smallexample
@include setjmp.c.texi
-@end example
+@end smallexample
The function @code{abort_to_main_loop} causes an immediate transfer of
control back to the main loop of the program, no matter where it is
@need 250
So, the general pattern for using @code{setjmp} looks something like:
-@example
+@smallexample
if (setjmp (@var{buffer}))
/* @r{Code to clean up after premature return.} */
@dots{}
else
/* @r{Code to be executed normally after setting up the return point.} */
@dots{}
-@end example
+@end smallexample
@node Non-Local Details, Non-Local Exits and Signals, Non-Local Intro, Non-Local Exits
@section Details of Non-Local Exits
@pindex setjmp.h
@comment setjmp.h
-@comment ANSI
+@comment ISO
@deftp {Data Type} jmp_buf
Objects of type @code{jmp_buf} hold the state information to
be restored by a non-local exit. The contents of a @code{jmp_buf}
@end deftp
@comment setjmp.h
-@comment ANSI
+@comment ISO
@deftypefn Macro int setjmp (jmp_buf @var{state})
When called normally, @code{setjmp} stores information about the
execution state of the program in @var{state} and returns zero. If
@end deftypefn
@comment setjmp.h
-@comment ANSI
-@deftypefun void longjmp (jmp_buf @var{state}, int @var{value})
+@comment ISO
+@deftypefun void longjmp (jmp_buf @var{state}, int @var{value})
This function restores current execution to the state saved in
@var{state}, and continues execution from the call to @code{setjmp} that
established that return point. Returning from @code{setjmp} by means of
@itemize @bullet
@item
As the test expression of a selection or iteration
-statement (such as @samp{if} or @samp{while}).
+statement (such as @samp{if}, @samp{switch}, or @samp{while}).
@item
As one operand of a equality or comparison operator that appears as the
nonzero @var{savesigs} flag, @code{siglongjmp} also restores the set of
blocked signals.
@end deftypefun
-