annotate docs/ccguide/longjmp.refentry @ 1417:b7b173926ea1

Changes and fixes by Robert Gault
author boisy
date Sun, 30 Nov 2003 22:25:56 +0000
parents 23db189b6713
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
1 <refentry id="longjmp">
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
2 <refnamediv>
568
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
3 <refname>Longjmp</refname>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
4 <refname>Setjmp</refname>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
5 <refpurpose>jump to another function</refpurpose>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
6 </refnamediv>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
7
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
8 <refsynopsisdiv>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
9 <funcsynopsis>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
10 <funcsynopsisinfo>
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
11 #include &lt;setjmp.h&gt;
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
12 </funcsynopsisinfo>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
13 <funcprototype>
568
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
14 <funcdef><function>setjmp</function></funcdef>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
15 <paramdef>jmp_buf <parameter>env</parameter></paramdef>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
16 </funcprototype>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
17
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
18 <funcprototype>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
19 <funcdef><function>longjmp</function></funcdef>
568
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
20 <paramdef>jmp_buf <parameter>env</parameter></paramdef>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
21 <paramdef>int <parameter>val</parameter></paramdef>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
22 </funcprototype>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
23 </funcsynopsis>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
24
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
25 </refsynopsisdiv>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
26
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
27 <refsect1><title>Description</title>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
28 <para>
568
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
29 These functions allow the return of program control directly to
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
30 a higher level function. They are most useful when dealing
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
31 with errors and interrupts encountered in a low level routine.
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
32 </para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
33 <para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
34 "Goto" in C has scope only in the function in which it is
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
35 used; i.e. the label which is the object of a "goto" may only
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
36 be in the same function. Control can only be transferred
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
37 elsewhere by means of the function call, which, of course
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
38 returns to the caller. In certain abnormal situations a
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
39 programmer would prefer to be able to start some section of
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
40 code again, but this would mean returning up a ladder of
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
41 function calls with error indications all the way.
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
42 </para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
43 <para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
44 Setjmp is used to "mark" a point in the program where a
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
45 subsequent longjmp can reach. It places in the buffer, defined
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
46 in the header file, enough information for longjmp to restore
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
47 the environment to that existing at the relevant call to
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
48 setjmp.
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
49 </para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
50 <para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
51 Longjmp is called with the environment buffer as an argument
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
52 and also, a value which can be used by the caller of setjmp as,
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
53 perhaps, an error status.
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
54 </para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
55 <para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
56 To set the system up, a function will call setjmp to set up the
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
57 buffer, and if the returned value is zero, the program will
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
58 know that the call was the "first time through". If, however,
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
59 the returned value is non-zero, it must be a longjmp returning
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
60 from some deeper level of the program.
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
61 </para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
62 <para>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
63 NOTE that the function calling setjmp must <emphasis>not have returned</emphasis>
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
64 at the time of calling longjmp, and the environment buffer must
23db189b6713 Several functions ready.
roug
parents: 468
diff changeset
65 be declared <emphasis>globally</emphasis>.
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
66 </para>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
67 </refsect1>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
68 </refentry>