• 全部
  • 问答

setjmp()的返回值和longjmp的第二个参数是不是同一个变量?

fsegsklk 2014-04-01 05:32:49
看书上貌似longjmp设置了第二个参数后,setjmp的返回值就自动变成那个值了
...全文
53 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qq120848369 2014-04-01
longjmp第二个参数就是setjmp的返回值,但不能传0,如果传0则被修正为1. 自己学会看man page:man longjmp
回复
fsegsklk 2014-04-01
你的帮助文档似乎并没有说明我的问题啊,而且残缺不全
回复
JiMoKuangXiangQu 2014-04-01
  Platform Builder for Microsoft Windows CE 5.0    

setjmpSee Also
longjmp | _fpreset

Requirements
OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.
Saves the current state of the program.

int setjmp( 
  jmp_buf env 
);
Parameters
env 
Variable in which environment is stored. 
Libraries
All versions of the C run-time libraries.

Return Values
setjmp 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.

Remarks
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.

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.

setjmp and longjmp do not support C++ object semantics. In C++ programs, use the C++ exception-handling mechanism. Using the longjmp or setjmp run-time routines in a C++ program will generate a link error if C++ exceptions are enabled using the /GX-Enable Exception Handling compiler option.

Requirements
OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also
longjmp | _fpreset




--------------------------------------------------------------------------------

Last updated on Wednesday, September 14, 2005

© 2005 Microsoft Corporation. All rights reserved.
  Platform Builder for Microsoft Windows CE 5.0    

longjmpSee Also
setjmp

Requirements
OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.
Restores stack environment and execution locale.

void longjmp( 
   jmp_buf env, 
   int value 
);
Parameters
env 
Variable in which environment is stored. 
value 
Value to be returned to setjmp call. 
Return Values
None.

Remarks
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.

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.

Call longjmp before the function that called setjmp returns; otherwise the results are unpredictable.

Observe the following restrictions when using longjmp: 

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. 
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. 
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. 
Using the longjmp or setjmp C runtime routines in a C++ file will generate a link error if C++ exceptions are enabled by using the /GX - Enable Exception Handling compiler option. This behavior is by design in Windows CE. 
Requirements
OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also
setjmp




--------------------------------------------------------------------------------

Last updated on Wednesday, September 14, 2005

© 2005 Microsoft Corporation. All rights reserved.

我想帮助文档总比我的描述更妥当。希望对LZ有所帮助。
回复
相关推荐
发帖
C语言
创建于2007-09-28

6.3w+

社区成员

C语言相关问题讨论
申请成为版主
帖子事件
创建了帖子
2014-04-01 05:32
社区公告
暂无公告