Skip to content

Commit 261e469

Browse files
authored
Merge pull request #917 from corob-msft/cr-longjmp
Fix longjmp docs for DD288352
2 parents d9d0d67 + 49a9eed commit 261e469

10 files changed

+459
-441
lines changed

.openpublishing.redirection.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"redirections": [
33
{
44
"source_path": "docs/assembler/arm/index.md",
@@ -240,6 +240,11 @@
240240
"redirect_url": "/cpp/cpp/extern-cpp",
241241
"redirect_document_id": false
242242
},
243+
{
244+
"source_path": "docs/cpp/using-structured-exception-handling-with-cpp.md",
245+
"redirect_url": "/cpp/cpp/exception-handling-differences",
246+
"redirect_document_id": false
247+
},
243248
{
244249
"source_path": "docs/cpp/support-for-cpp11-14-17-features-modern-cpp.md",
245250
"redirect_url": "/cpp/visual-cpp-language-conformance",

docs/build/reference/eh-exception-handling-model.md

Lines changed: 93 additions & 98 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "longjmp | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "08/14/2018"
55
ms.technology: ["cpp-standard-libraries"]
66
ms.topic: "reference"
77
apiname: ["longjmp"]
@@ -17,7 +17,7 @@ ms.workload: ["cplusplus"]
1717
---
1818
# longjmp
1919

20-
Restores stack environment and execution locale.
20+
Restores the stack environment and execution locale set by a `setjmp` call.
2121

2222
## Syntax
2323

@@ -30,27 +30,39 @@ void longjmp(
3030

3131
### Parameters
3232

33-
*env*
33+
*env*
3434
Variable in which environment is stored.
3535

36-
*value*
37-
Value to be returned to **setjmp** call.
36+
*value*
37+
Value to be returned to `setjmp` call.
3838

3939
## Remarks
4040

41-
The **longjmp** function restores a stack environment and execution locale previously saved in *env* by **setjmp**. **setjmp** and **longjmp** provide a way to execute a nonlocal **goto**; they are typically used to pass execution control to error-handling or recovery code in a previously called routine without using the normal call and return conventions.
41+
The **longjmp** function restores a stack environment and execution locale previously saved in *env* by `setjmp`. `setjmp` and **longjmp** provide a way to execute a nonlocal **goto**; they are typically used to pass execution control to error-handling or recovery code in a previously called routine without using the normal call and return conventions.
4242

43-
A call to **setjmp** causes the current stack environment to be saved in *env*. A subsequent call to **longjmp** restores the saved environment and returns control to the point immediately following the corresponding **setjmp** call. Execution resumes as if *value* had just been returned by the **setjmp** call. The values of all variables (except register variables) that are accessible to the routine receiving control contain the values they had when **longjmp** was called. The values of register variables are unpredictable. The value returned by **setjmp** must be nonzero. If *value* is passed as 0, the value 1 is substituted in the actual return.
43+
A call to `setjmp` causes the current stack environment to be saved in *env*. A subsequent call to **longjmp** restores the saved environment and returns control to the point immediately following the corresponding `setjmp` call. Execution resumes as if *value* had just been returned by the `setjmp` call. The values of all variables (except register variables) that are accessible to the routine receiving control contain the values they had when **longjmp** was called. The values of register variables are unpredictable. The value returned by `setjmp` must be nonzero. If *value* is passed as 0, the value 1 is substituted in the actual return.
4444

45-
Call **longjmp** before the function that called **setjmp** returns; otherwise the results are unpredictable.
45+
**Microsoft Specific**
46+
47+
In Microsoft C++ code on Windows, **longjmp** uses the same stack-unwinding semantics as exception-handling code. It is safe to use in the same places that C++ exceptions can be raised. However, this usage is not portable, and comes with some important caveats.
48+
49+
Only call **longjmp** before the function that called `setjmp` returns; otherwise the results are unpredictable.
4650

4751
Observe the following restrictions when using **longjmp**:
4852

49-
- Do not assume that the values of the register variables will remain the same. The values of register variables in the routine calling **setjmp** may not be restored to the proper values after **longjmp** is executed.
53+
- Do not assume that the values of the register variables will remain the same. The values of register variables in the routine calling `setjmp` may not be restored to the proper values after **longjmp** is executed.
54+
55+
- Do not use **longjmp** to transfer control out of an interrupt-handling routine unless the interrupt is caused by a floating-point exception. In this case, a program may return from an interrupt handler via **longjmp** if it first reinitializes the floating-point math package by calling [_fpreset](fpreset.md).
56+
57+
- Do not use **longjmp** to transfer control from a callback routine invoked directly or indirectly by Windows code.
5058

51-
- Do not use **longjmp** to transfer control out of an interrupt-handling routine unless the interrupt is caused by a floating-point exception. In this case, a program may return from an interrupt handler via **longjmp** if it first reinitializes the floating-point math package by calling **_fpreset**.
59+
- If the code is compiled by using **/EHs** or **/EHsc** and the function that contains the **longjmp** call is **noexcept** then local objects in that function may not be destructed during the stack unwind.
5260

53-
**Note** Be careful when using **setjmp** and **longjmp** in C++ programs. Because these functions do not support C++ object semantics, it is safer to use the C++ exception-handling mechanism.
61+
**END Microsoft Specific**
62+
63+
> [!NOTE]
64+
> In portable C++ code, you can't assume `setjmp` and `longjmp` support C++ object semantics. Specifically, a `setjmp`/`longjmp` call pair has undefined behavior if replacing the `setjmp` and `longjmp` by **catch**
65+
and **throw** would invoke any non-trivial destructors for any automatic objects. In C++ programs, we recommend you use the C++ exception-handling mechanism.
5466

5567
For more information, see [Using setjmp and longjmp](../../cpp/using-setjmp-longjmp.md).
5668

@@ -62,15 +74,11 @@ For more information, see [Using setjmp and longjmp](../../cpp/using-setjmp-long
6274

6375
For additional compatibility information, see [Compatibility](../../c-runtime-library/compatibility.md).
6476

65-
## Libraries
66-
67-
All versions of the [C run-time libraries](../../c-runtime-library/crt-library-features.md).
68-
6977
## Example
7078

7179
See the example for [_fpreset](fpreset.md).
7280

7381
## See also
7482

75-
[Process and Environment Control](../../c-runtime-library/process-and-environment-control.md)<br/>
76-
[setjmp](setjmp.md)<br/>
83+
[Process and Environment Control](../../c-runtime-library/process-and-environment-control.md)
84+
[setjmp](setjmp.md)

docs/c-runtime-library/reference/setjmp.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "setjmp | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "08/14/2018"
55
ms.technology: ["cpp-standard-libraries"]
66
ms.topic: "reference"
77
apiname: ["setjmp"]
@@ -29,22 +29,30 @@ int setjmp(
2929

3030
### Parameters
3131

32-
*env*<br/>
32+
*env*
3333
Variable in which environment is stored.
3434

3535
## Return Value
3636

37-
Returns 0 after saving the stack environment. If **setjmp** returns as a result of a **longjmp** call, it returns the **value** argument of **longjmp**, or if the **value** argument of **longjmp** is 0, **setjmp** returns 1. There is no error return.
37+
Returns 0 after saving the stack environment. If **setjmp** returns as a result of a `longjmp` call, it returns the *value* argument of `longjmp`, or if the *value* argument of `longjmp` is 0, **setjmp** returns 1. There is no error return.
3838

3939
## Remarks
4040

41-
The **setjmp** function saves a stack environment, which you can subsequently restore, using **longjmp**. When used together, **setjmp** and **longjmp** provide a way to execute a non-local **goto**. They are typically used to pass execution control to error-handling or recovery code in a previously called routine without using the normal calling or return conventions.
41+
The **setjmp** function saves a stack environment, which you can subsequently restore, using `longjmp`. When used together, **setjmp** and `longjmp` provide a way to execute a non-local **goto**. They are typically used to pass execution control to error-handling or recovery code in a previously called routine without using the normal calling or return conventions.
4242

43-
A call to **setjmp** saves the current stack environment in *env*. A subsequent call to **longjmp** restores the saved environment and returns control to the point just after the corresponding **setjmp** call. All variables (except register variables) accessible to the routine receiving control contain the values they had when **longjmp** was called.
43+
A call to **setjmp** saves the current stack environment in *env*. A subsequent call to `longjmp` restores the saved environment and returns control to the point just after the corresponding **setjmp** call. All variables (except register variables) accessible to the routine receiving control contain the values they had when `longjmp` was called.
4444

4545
It is not possible to use **setjmp** to jump from native to managed code.
4646

47-
**Note** **setjmp** and **longjmp** do not support C++ object semantics. In C++ programs, use the C++ exception-handling mechanism.
47+
**Microsoft Specific**
48+
49+
In Microsoft C++ code on Windows, **longjmp** uses the same stack-unwinding semantics as exception-handling code. It is safe to use in the same places that C++ exceptions can be raised. However, this usage is not portable, and comes with some important caveats. For details, see [longjmp](longjmp.md).
50+
51+
**END Microsoft Specific**
52+
53+
> [!NOTE]
54+
> In portable C++ code, you can't assume `setjmp` and `longjmp` support C++ object semantics. Specifically, a `setjmp`/`longjmp` call pair has undefined behavior if replacing the `setjmp` and `longjmp` by **catch**
55+
and **throw** would invoke any non-trivial destructors for any automatic objects. In C++ programs, we recommend you use the C++ exception-handling mechanism.
4856

4957
For more information, see [Using setjmp and longjmp](../../cpp/using-setjmp-longjmp.md).
5058

@@ -62,6 +70,5 @@ See the example for [_fpreset](fpreset.md).
6270

6371
## See also
6472

65-
[Process and Environment Control](../../c-runtime-library/process-and-environment-control.md)<br/>
66-
[longjmp](longjmp.md)<br/>
67-
[_setjmp3](../../c-runtime-library/setjmp3.md)<br/>
73+
[Process and Environment Control](../../c-runtime-library/process-and-environment-control.md)
74+
[longjmp](longjmp.md)

docs/cpp/TOC.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
#### [Unhandled C++ Exceptions](unhandled-cpp-exceptions.md)
257257
#### [Mixing C (Structured) and C++ Exceptions](mixing-c-structured-and-cpp-exceptions.md)
258258
##### [Using setjmp-longjmp](using-setjmp-longjmp.md)
259-
##### [Exception Handling Differences](exception-handling-differences.md)
259+
##### [Handle structured exceptions in C++](exception-handling-differences.md)
260260
### [Structured Exception Handling (C/C++)](structured-exception-handling-c-cpp.md)
261261
#### [Writing an Exception Handler](writing-an-exception-handler.md)
262262
##### [try-except Statement](try-except-statement.md)
@@ -269,7 +269,6 @@
269269
##### [Cleaning up Resources](cleaning-up-resources.md)
270270
##### [Timing of Exception Handling: A Summary](timing-of-exception-handling-a-summary.md)
271271
##### [Restrictions on Termination Handlers](restrictions-on-termination-handlers.md)
272-
#### [Using Structured Exception Handling with C++](using-structured-exception-handling-with-cpp.md)
273272
### [Transporting Exceptions Between Threads](transporting-exceptions-between-threads.md)
274273
## [Assertion and User-Supplied Messages](assertion-and-user-supplied-messages-cpp.md)
275274
### [static_assert](static-assert.md)

0 commit comments

Comments
 (0)