跳远 [英] longjump

查看:50
本文介绍了跳远的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!我只是不明白longjmp的工作方式..我读了这篇文档:
http://www.acm.uiuc.edu/webmonkeys/b...guide/2.8.html


但我只是不喜欢不知道为什么地址不是任何参数传递的变量值,改变了它的价值......


我明白了环境问题,我认为这意味着所有变量

都会被保存,然后使用这个环境进行恢复,但我只是没有看到

其中''值''改变它的价值......

我知道使用跳跃不是一个好主意,但我希望对C语言有一个深入的了解b
,所有它不起眼的角落


谢谢!

解决方案

文章< W2 ** ******************@wagner.videotron.net> ;,埃里克写道:

嗨!我只是不明白longjmp的工作方式..我读了这篇文档:
http://www.acm.uiuc.edu/webmonkeys/b...guide/2.8.html

但我只是没看到为什么变量值,地址没有在任何参数中传递,改变了它的价值...


我认为你应该留下地址出于此。在这个例子中没有

指针。

我理解环境的事情,我认为这意味着所有变量
都会被保存,然后使用这个环境进行恢复,但我只是没有看到
价值改变了它的价值......




变量''value''改变了它在行上的价值

" value = setjmp(environment_buffer);"在main()中,你在some_function()中的longjmp()之后登陆

。它的值为5

,因为这是你在$ j $ b longjmp()调用中指定的setjmp()的返回值。

-

Andreas K?h?ri


Eric写道:

嗨!我只是不明白longjmp的工作方式..我读了这篇文档:
http://www.acm.uiuc.edu/webmonkeys/b...guide/2.8.html

但我只是没看到为什么变量值,地址没有在任何参数中传递,改变了它的价值......

我理解环境的事情,我认为这意味着所有的变量<保存,然后使用此环境恢复,


不,这根本不是意味着。

setjmp或longjmp不会保存或恢复变量。


7.13.2.1 longjmp函数


[ #3]所有可访问的对象都具有调用时间值的价值

longjmp被调用,除了对象的值为

自动存储持续时间是函数的本地值/>
包含对应的setjmp宏的调用

没有volatile限定类型并且在setjmp调用和longjmp调用之间已经更改了



不确定。

但我只是没看到
价值改变了它的价值......

我知道使用跳跃不是一个好主意,但我希望对C语言有深入的了解,以及所有它的模糊角落




这个例子甚至不合法:


7.13.1.1 setjmp宏


[#4]调用setjmp宏sha ll仅出现在

以下某个上下文中:


- 选择的整个控制表达式或

迭代语句;


- 关系或等式运算符的一个操作数,

另一个操作数是一个整数常量表达式,

结果表达式是选择或迭代语句的整个控制

表达式;


- 一元的操作数!运算符生成的

表达式是

选择或迭代语句的整个控制表达式;或者


- 表达式声明的整个表达式

(可能转为无效)。


注意这不允许setjmp调用显示为赋值表达式的右侧




除此之外,重点是setjmp可能返回不止一次。

初始调用返回0.后来,当你调用longjmp时,效果

是导致程序从setjmp调用继续执行

再次,但这次使用不同的返回值。所以来自setjmp的返回值

告诉你它是从直接调用返回

还是从后来的longjmp调用返回。


-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近发布的地址。





ok谢谢大家!


-Eric


" Kevin Goodsell" <我们********************* @ neverbox.com> aécritdansle

message de news:4T ******************* @ newsread2.news.pas.eart hlink.net ...

Eric写道:

嗨!我只是不明白longjmp的工作方式..我读了这篇文档:
http://www.acm.uiuc.edu/webmonkeys/b...guide/2.8.html

但我只是没看到为什么变量值,地址没有在任何参数中传递,改变了它的价值......

我理解环境的事情,我认为这意味着所有的
变量被保存,然后使用这个环境恢复,



不,这根本不意味着。
setjmp或longjmp不会保存或恢复变量。

7.13.2.1 longjmp函数

[#3]所有可访问的对象都具有截至时间的值
调用了longjmp,除了
自动存储持续时间的对象值是函数本地的
包含对应的setjmp宏的调用
没有volatile-限定类型并且在setjmp调用和longjmp调用之间进行了更改
不确定。

但我只是看不到
在哪里' '价值''改变了它的价值......

我知道使用跳跃不是一个好主意,但我希望对C语言有深入的了解,这一切都是模糊不清的角落



这个例子甚至都不合法:

7.13.1.1 setjmp宏
[#4]应该调用setjmp宏的调用ar只能在以下某个上下文中使用:

- 选择或
迭代语句的整个控制表达式;

- 一个操作数一个关系或等于运算符与另一个操作数的整数常量表达式,其结果表达式是选择或迭代语句的整个控制表达式;
- 一元的操作数!运算符,结果
表达式是
选择或迭代语句的整个控制表达式;或者

- 表达式语句的整个表达式
(可能转换为void)。

请注意,这不允许setjmp调用显示为对于赋值表达式的一面。

除此之外,关键是setjmp可能会多次返回。
初始调用返回0.后来,当你调用时longjmp,效果
是让程序再次从setjmp调用继续执行,但这次使用不同的返回值。所以来自setjmp的返回值
告诉你它是从直接调用返回还是从后来的longjmp调用返回。

-Kevin
-
我的电子邮件地址有效,但会定期更改。
要联系我,请使用最近发布的地址。



Hi ! I just do not understand how longjmp works.. I read this docs :
http://www.acm.uiuc.edu/webmonkeys/b...guide/2.8.html

but I just don''t see why the variable value, which the address is not
passed in any argument, changed it''s value...

I understood the environnement thing, I think that means all the variables
are saved and then restored using this environnement, but I just don''t see
where ''value'' changed it''s value...
I know using jumps are not a good idea, but I want to have a in-depth
knowledge of the C langage, and all it''s obscure corners

Thanks !

解决方案

In article <W2********************@wagner.videotron.net>, Eric wrote:

Hi ! I just do not understand how longjmp works.. I read this docs :
http://www.acm.uiuc.edu/webmonkeys/b...guide/2.8.html

but I just don''t see why the variable value, which the address is not
passed in any argument, changed it''s value...
I think you should leave "addresses" out of this. There are no
pointer in this example.
I understood the environnement thing, I think that means all the variables
are saved and then restored using this environnement, but I just don''t see
where ''value'' changed it''s value...



The variable ''value'' changed its value on the line
"value=setjmp(environment_buffer);" in main(), where you landed
after the longjmp() in some_function(). It gets the value 5
since that''s the return value of setjmp() that you specified in
the longjmp() call.
--
Andreas K?h?ri


Eric wrote:

Hi ! I just do not understand how longjmp works.. I read this docs :
http://www.acm.uiuc.edu/webmonkeys/b...guide/2.8.html

but I just don''t see why the variable value, which the address is not
passed in any argument, changed it''s value...

I understood the environnement thing, I think that means all the variables
are saved and then restored using this environnement,
No, it does not mean that at all. Variables are not saved or restored by
setjmp or longjmp.

7.13.2.1 The longjmp function

[#3] All accessible objects have values as of the time
longjmp was called, except that the values of objects of
automatic storage duration that are local to the function
containing the invocation of the corresponding setjmp macro
that do not have volatile-qualified type and have been
changed between the setjmp invocation and longjmp call are
indeterminate.
but I just don''t see
where ''value'' changed it''s value...
I know using jumps are not a good idea, but I want to have a in-depth
knowledge of the C langage, and all it''s obscure corners



The example isn''t even legal:

7.13.1.1 The setjmp macro

[#4] An invocation of the setjmp macro shall appear only in
one of the following contexts:

-- the entire controlling expression of a selection or
iteration statement;

-- one operand of a relational or equality operator with
the other operand an integer constant expression, with
the resulting expression being the entire controlling
expression of a selection or iteration statement;

-- the operand of a unary ! operator with the resulting
expression being the entire controlling expression of a
selection or iteration statement; or

-- the entire expression of an expression statement
(possibly cast to void).

Note that this does not allow a setjmp invocation to appear as the right
side of an assignment expression.

But aside from that, the point is that setjmp may return more than once.
The initial call returns 0. Later, when you invoke longjmp, the effect
is to cause the program to continue executing from the setjmp call
again, but this time with a different return value. So the return value
from setjmp tells you whether it is returning from a direct invocation
or from a later longjmp invocation.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.




ok thanks everyone !

-Eric

"Kevin Goodsell" <us*********************@neverbox.com> a écrit dans le
message de news:4T*******************@newsread2.news.pas.eart hlink.net...

Eric wrote:

Hi ! I just do not understand how longjmp works.. I read this docs :
http://www.acm.uiuc.edu/webmonkeys/b...guide/2.8.html

but I just don''t see why the variable value, which the address is not
passed in any argument, changed it''s value...

I understood the environnement thing, I think that means all the variables are saved and then restored using this environnement,



No, it does not mean that at all. Variables are not saved or restored by
setjmp or longjmp.

7.13.2.1 The longjmp function

[#3] All accessible objects have values as of the time
longjmp was called, except that the values of objects of
automatic storage duration that are local to the function
containing the invocation of the corresponding setjmp macro
that do not have volatile-qualified type and have been
changed between the setjmp invocation and longjmp call are
indeterminate.

but I just don''t see
where ''value'' changed it''s value...
I know using jumps are not a good idea, but I want to have a in-depth
knowledge of the C langage, and all it''s obscure corners



The example isn''t even legal:

7.13.1.1 The setjmp macro

[#4] An invocation of the setjmp macro shall appear only in
one of the following contexts:

-- the entire controlling expression of a selection or
iteration statement;

-- one operand of a relational or equality operator with
the other operand an integer constant expression, with
the resulting expression being the entire controlling
expression of a selection or iteration statement;

-- the operand of a unary ! operator with the resulting
expression being the entire controlling expression of a
selection or iteration statement; or

-- the entire expression of an expression statement
(possibly cast to void).

Note that this does not allow a setjmp invocation to appear as the right
side of an assignment expression.

But aside from that, the point is that setjmp may return more than once.
The initial call returns 0. Later, when you invoke longjmp, the effect
is to cause the program to continue executing from the setjmp call
again, but this time with a different return value. So the return value
from setjmp tells you whether it is returning from a direct invocation
or from a later longjmp invocation.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.



这篇关于跳远的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆