-
Notifications
You must be signed in to change notification settings - Fork 174
csetjmpリファレンスの追加
#1618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
csetjmpリファレンスの追加
#1618
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # csetjmp | ||
| * csetjmp[meta header] | ||
|
|
||
| `<csetjmp>`ヘッダでは、非ローカルジャンプのための機能を定義する。非ローカルジャンプは、関数呼び出しのスタックを遡って、特定のポイントにジャンプすることを可能にする機能である。 | ||
|
|
||
| ## 型 | ||
| | 名前 | 説明 | 対応バージョン | | ||
| |------|------| ----------------| | ||
| | [`jmp_buf`](csetjmp/jmp_buf.md) | 非ローカルジャンプのための環境を保存するための型 | | | ||
|
|
||
| ## マクロ | ||
| | 名前 | 説明 | 対応バージョン | | ||
| |------|------|----------------| | ||
| | [`setjmp`](csetjmp/setjmp.md) | 現在の環境を保存するためのマクロ | | | ||
| | [`__STDC_VERSION_SETJMP_H__`](csetjmp/stdc_version_setjmp_h.md) | C23に準拠していることを示すマクロ | C++26 | | ||
|
|
||
|
|
||
| ## 関数 | ||
| | 名前 | 説明 | 対応バージョン | | ||
| |------|------|----------------| | ||
| | [`longjmp`](csetjmp/longjmp.md) | `setjmp()`で保存された環境を復元し、ジャンプするための関数 | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # jmp_buf | ||
| * std[meta namespace] | ||
| * csetjmp[meta header] | ||
| * type-alias[meta id-type] | ||
|
|
||
| ```cpp | ||
| namespace std { | ||
| using jmp_buf = unspecified; | ||
| } | ||
| ``` | ||
| * unspecified[italic] | ||
|
|
||
| ## 概要 | ||
|
|
||
| `jmp_buf`は、非ローカルジャンプ(関数を跨いだジャンプ)を実現するために、現在の実行環境を保存するための配列型である。 | ||
|
|
||
| [`setjmp()`](setjmp.md)マクロによって現在の環境がこの型に保存され、後に[`longjmp()`](longjmp.md)関数がその環境を復元するために使用される。 | ||
|
|
||
| ## 例 | ||
|
|
||
| ```cpp example | ||
| #include <iostream> | ||
| #include <csetjmp> | ||
|
|
||
| std::jmp_buf env; | ||
|
|
||
| void inner_function() { | ||
| std::cout << "何らかのエラー" << std::endl; | ||
| std::longjmp(env, 42); | ||
| } | ||
|
|
||
| int main () { | ||
| if (setjmp(env) == 0) { | ||
| inner_function(); | ||
| } else { | ||
| std::cout << "エラーから復帰しました" << std::endl; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| ``` | ||
| * std::jmp_buf[color ff0000] | ||
| * std::longjmp[link longjmp.md] | ||
| * setjmp[link setjmp.md] | ||
|
|
||
| ### 出力 | ||
| ``` | ||
| 何らかのエラー | ||
| エラーから復帰しました | ||
| ``` | ||
|
|
||
| ## 関連項目 | ||
| - [`longjmp()`](longjmp.md) | ||
| - [`setjmp()`](setjmp.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # longjmp | ||
| * csetjmp[meta header] | ||
| * std[meta namespace] | ||
| * function[meta id-type] | ||
|
|
||
| ```cpp | ||
| namespace std { | ||
| [[noreturn]] void longjmp(jmp_buf env, int val); | ||
| } | ||
| ``` | ||
|
|
||
| ## 概要 | ||
|
|
||
| 引数`env`に保存された実行環境を復元し、対応する[`setjmp()`](setjmp.md)の呼び出し地点へプログラムの制御を移す(非ローカルジャンプ)。 | ||
|
|
||
| ## 効果 | ||
|
|
||
| * `setjmp()`によって第一引数`env`に保存された実行環境(スタックポインタ、プログラムカウンタ等)を復元する。 | ||
|
K10-K10 marked this conversation as resolved.
|
||
|
|
||
| * プログラムの実行地点を、対応する[`setjmp()`](setjmp.md)の呼び出し地点へジャンプさせる。 | ||
|
|
||
| * ジャンプ先の[`setjmp()`](setjmp.md)は、この関数の第二引数`val`を戻り値として返す。ただし、`val`が0の場合は1を返す。 | ||
|
|
||
| ## 戻り値 | ||
|
|
||
| この関数は決して返らない。 | ||
|
|
||
| ## 備考 | ||
|
|
||
| 以下の場合、動作は未定義である。 | ||
| * 対応する`setjmp` と `longjmp` の間で、自動記憶域期間を持つ非トリビアルなデストラクタを持つオブジェクトの生存期間が開始し、終了しない場合(ジャンプによってデストラクタを飛ばす場合) | ||
| * コルーチンのサスペンションコンテキスト内で呼び出された場合 | ||
| * 対応する`setjmp`が存在しない場合(`env`が有効な環境を保存していない場合) | ||
| * `longjmp`は、対応する`setjmp`の呼び出しから同一スレッド内で呼び出されなければならない。異なるスレッドから呼び出された場合 | ||
| * `setjmp`を呼び出した関数の実行が終了している場合 | ||
|
|
||
| また、`volatile`修飾子のついていない`setjmp`を呼び出した関数に対してローカルな変数で、その値が`setjmp`から`longjmp`の呼び出しの間で変更されたものがある場合、その変数の値は不定となる。 | ||
|
|
||
| ## 例 | ||
|
|
||
| ```cpp example | ||
| #include <iostream> | ||
| #include <csetjmp> | ||
|
|
||
| std::jmp_buf env; | ||
|
|
||
| void inner_function() { | ||
| std::cout << "何らかのエラー" << std::endl; | ||
| std::longjmp(env, 0); // valが0なので、setjmpは1を返す | ||
| } | ||
|
|
||
| int main () { | ||
| if (setjmp(env) == 0) { | ||
| inner_function(); | ||
| } else { | ||
| std::cout << "エラーから復帰しました" << std::endl; | ||
| } | ||
| return 0; | ||
| } | ||
| ``` | ||
| * std::longjmp[color ff0000] | ||
| * setjmp[link setjmp.md] | ||
| * std::jmp_buf[link jmp_buf.md] | ||
|
|
||
| ### 出力 | ||
|
|
||
| ``` | ||
| 何らかのエラー | ||
| エラーから復帰しました | ||
| ``` | ||
|
|
||
| ## 関連項目 | ||
| * [`jmp_buf`](jmp_buf.md) | ||
| * [`setjmp`](setjmp.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # setjmp | ||
| * csetjmp[meta header] | ||
| * macro[meta id-type] | ||
|
|
||
| ```cpp | ||
| #define setjmp(env) unspecified | ||
| ``` | ||
|
K10-K10 marked this conversation as resolved.
|
||
| * unspecified[italic] | ||
|
|
||
| ## 概要 | ||
|
|
||
| 現在の環境を引数`env`に保存するマクロ。 | ||
| `env`は、[`jmp_buf`](jmp_buf.md)型のオブジェクトでなければならない。 | ||
|
|
||
| ## 事前条件 | ||
|
|
||
| このマクロは以下の文脈でのみ現れる。 | ||
|
|
||
| 1. `if`文、`switch`文やループの条件全体 | ||
| 2. 関係演算子または等価演算子のオペランドの一つ(もう一つのオペランドは整数定数)で、その結果式が1を満たす場合 | ||
| 3. `!`のオペランドであり、その式が1を満たす場合 | ||
| 4. 式文の式全体(`void`型へのキャストを含む) | ||
|
|
||
| 上記以外の箇所での呼び出しは未定義の動作となる。 | ||
|
|
||
| ## 戻り値 | ||
|
|
||
| 直接マクロが呼び出された場合、0を返す。 | ||
| それ以外([`longjmp`](longjmp.md)関数から)の呼び出しでは非0を返す。 | ||
| なお、[`longjmp`](longjmp.md)関数の第二引数が0の場合は、1を返す。 | ||
|
|
||
| ## 備考 | ||
|
|
||
| * 対応する`setjmp` と `longjmp` の間で、自動記憶域期間を持つ非トリビアルなデストラクタを持つオブジェクトの生存期間が開始し、終了しない場合(ジャンプによってデストラクタを飛ばす場合)、その動作は未定義である。 | ||
| * コルーチンのサスペンションコンテキスト内で呼び出された場合、動作は未定義である。 | ||
|
|
||
| また、`volatile`修飾子のついていない`setjmp`を呼び出した関数に対してローカルな変数で、その値が`setjmp`から`longjmp`の呼び出しの間で変更されたものがある場合、その変数の値は不定となる。 | ||
|
|
||
|
|
||
|
akinomyoga marked this conversation as resolved.
|
||
| ## 例 | ||
|
|
||
| ```cpp example | ||
| #include <iostream> | ||
| #include <csetjmp> | ||
|
|
||
| std::jmp_buf env; | ||
|
|
||
| void inner_function() { | ||
| std::cout << "何らかのエラー" << std::endl; | ||
| std::longjmp(env, 42); | ||
| } | ||
|
|
||
| int main () { | ||
| if (setjmp(env) == 0) { | ||
| inner_function(); | ||
| } else { | ||
| std::cout << "エラーから復帰しました" << std::endl; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| ``` | ||
| * setjmp[color ff0000] | ||
| * std::longjmp[link longjmp.md] | ||
| * std::jmp_buf[link jmp_buf.md] | ||
|
|
||
|
|
||
| ### 出力 | ||
|
|
||
| ``` | ||
| 何らかのエラー | ||
| エラーから復帰しました | ||
| ``` | ||
|
|
||
| ## 参照 | ||
|
|
||
| [MSC22-C. setjmp()、longjmp() の機能を安全に使用する](https://www.jpcert.or.jp/sc-rules/c-msc22-c.html#:~:text=%E4%BB%A3%E5%85%A5%E6%96%87%E3%81%A7%20setjmp()%20%E3%82%92%E5%91%BC%E3%81%B3%E5%87%BA%E3%81%97%E3%81%A6%E3%81%8A%E3%82%8A%E3%80%81%E7%B5%90%E6%9E%9C%E3%81%A8%E3%81%97%E3%81%A6%E6%9C%AA%E5%AE%9A%E7%BE%A9%E3%81%AE%E5%8B%95%E4%BD%9C%E3%81%8C%E5%BC%95%E3%81%8D%E8%B5%B7%E3%81%93%E3%81%95%E3%82%8C%E3%82%8B) | ||
|
|
||
| ## 関連項目 | ||
| - [jmp_buf](/reference/csetjmp/jmp_buf.md) | ||
| - [longjmp](/reference/csetjmp/longjmp.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # \_\_STDC_VERSION_SETJMP_H__ | ||
| * csetjmp[meta header] | ||
| * macro[meta id-type] | ||
| * cpp26[meta cpp] | ||
|
|
||
| ```cpp | ||
| #define __STDC_VERSION_SETJMP_H__ 202311L | ||
| ``` | ||
|
|
||
| ## 概要 | ||
| `<csetjmp>`ヘッダがC23の基準に準拠していることを示すマクロ。 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.