
C++で書いているソース内において、
setjmp・longjmpを挿入し、
プログラムを実行してみましたところ、
「セグメンテーション違反」ということで止まってしまいました。
どうして、そうなってしまったのか?が、
自分では解決に至らず、
質問させていただきます。
挿入す前はエラーなど出ませんでしたが、
長々と確認してみたところ、
「セグメンテーション違反」となった部分は、
やはり、挿入したsetjmp・longjmpの部分でした。
「test.c」というファイル内にて、
以下のとおり、setjmpをしかけております。
========================================
jmp_buf env;
if (setjmp(env) == 0) {
std::string food = get_air(key);
} else {
printf("test OK \n");
}
========================================
そして、
「test.c」とは別のファイルなんですが、
以下のとおり、
「get_air.h」というファイルにて、
「longjmp」をしかけております。
========================================
if (iterator != _container_air.end()) {
printf("## [info]get_the_air \n");
}
printf("## [info]fail to get \n");
longjmp(env, 1);
printf("Here is out of area.\n");
}
========================================
周囲に質問できる人が皆無なため、
「特に問題なさそうだよ」というのでも結構ですので、
何かアドバイスいただけると大変ありがたいです。
宜しくお願い致します。
No.2
- 回答日時:
#1さんがご回答なさっている通りです。
「
C++ Language Reference
Using setjmp/longjmp
Do not use setjmp and longjmp in C++ programs; these functions do not support C++ object semantics. Also, using these functions in C++ programs may degrade performance by preventing optimization on local variables. Use the C++ exception handling try/catch constructs instead.
If you must use setjmp/longjmp in a C++ program, the interaction between these functions and C++ exception handling requires that you include SETJMP.H or SETJMPEX.H. Destructors for local objects will be called during the stack unwind if you compile with /EH. If you compile with /EHs and one of your functions call a function that uses nothrow, and if the function that uses nothrow calls longjmp, the destructor unwind may not occur, depending on the optimizer.
Also, if you intend your code to be portable, do not rely on correct destruction of frame-based objects when executing a nonlocal goto using a call to longjmp.
」(from msdn)
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
#defineが使用するメモリ領域に...
-
printf による16進表示について
-
Enterキーを押されたら次の処理...
-
0x8, スペース, 0x8をプログラ...
-
タイムカードのシステムを作り...
-
HANDLEのエラー
-
最早開始時間と最遅完了時刻を...
-
20'(角度)の計算がわかりま...
-
信頼区間の1.96や1.65ってどこ...
-
Aの値からBの値を除するとは??
-
数字以外が入力されたらエラー...
-
値差の%計算方法について
-
「Aに対するBの割合」と「Aに対...
-
cout関数を使っているのですが...
-
2÷3などの余りについて
-
構造体の勉強中です 合計点の高...
-
main.c:7:43: warning: implici...
-
C言語 エラーの原因がわからな...
-
CTabCtrl:TABインデックス単位...
-
ExcelでPC(パソコン)によって...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
Enterキーを押されたら次の処理...
-
【C言語】全角文字の配列を、全...
-
#defineが使用するメモリ領域に...
-
printf による16進表示について
-
reallocでエラー
-
エラーについて質問です。
-
static付き宣言の初期化
-
char型2つを結合し、short型に...
-
WinInetのInternetOpenUrl関数...
-
空白を含んだ文字列がうまく格...
-
C言語でファイルから複素数の値...
-
C言語で複数列のデータを1列の...
-
Cプログラムについて
-
C++で指定文字列のカウント方法...
-
プログラミング ポインタを使...
-
ビルドエラーの対処がわからな...
-
リストの作成と出力(C言語)
-
setjmp・longjmpに関しまして
-
C言語でのCSVファイルの読み出...
-
2進数の表示
おすすめ情報