状态机和协同程序 [英] State Machines and Coroutines

查看:110
本文介绍了状态机和协同程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

状态机和协同程序


goto上的另一个主题:让我想问一下......本着

状态机和协同程序的精神,这个N00b到C想知道是否

setjmp / longjmp是打破常规的唯一方法;离开

函数并重新进入堆栈状态。


我问这个是因为我只是简单地回顾了这些函数/>
我相信longjmp只返回指定的int。因此我将会天真地假设指针会/可能用于返回或改变
变量。我想我记得有关挥发性

限定词的内容也在使用。


谢谢你,

Deiter

State Machines and Coroutines

The other thread on goto: Lead me to want to ask... In the spirit of
state machines and coroutines, This n00b to C would like to know if
setjmp/longjmp are the only way to break out of a routine; leave the
function and re-enter the stack state.

I ask this because I''ve only briefly, as yet, reviewed these functions
and I believe longjmp will only return a designated int. Therefore I
would naively assume pointers would/could be used to return or alter
variables. I think I remember something mentioned about volatile
qualifiers being used as well.

Thank you,
Deiter

推荐答案



Deiter写道:

Deiter wrote:
状态机和协同程序

其他goto上的帖子:引导我想问......在状态机和协同程序的精神中,这个n00b到C想知道是否
setjmp / longjmp是打破的唯一方法例程;离开
函数并重新进入堆栈状态。

我问这个是因为我只是简单地回顾了这些函数
我相信longjmp只会返回一个指定的int。因此我会天真地假设指针会/可能用于返回或改变变量。我想我记得有关挥发性
限定词的内容也被使用了。
State Machines and Coroutines

The other thread on goto: Lead me to want to ask... In the spirit of
state machines and coroutines, This n00b to C would like to know if
setjmp/longjmp are the only way to break out of a routine; leave the
function and re-enter the stack state.

I ask this because I''ve only briefly, as yet, reviewed these functions
and I believe longjmp will only return a designated int. Therefore I
would naively assume pointers would/could be used to return or alter
variables. I think I remember something mentioned about volatile
qualifiers being used as well.




嗨Deiter,

我不是完全确定你在这里想要做什么,但听起来好像你想要在你到达终点之前退出一个功能吗?


你可以退出具有return(var)语句的任何点的函数。对于

示例,如果您的基金返回一个整数,您可以调用return(0)。


例如


int test_fnc(int input)

{

if(input> = 1)

return(1);

其他

返回(0);

}


返回参数后,该函数将从堆栈中删除。 />
希望有所帮助,

Alastair



Hi Deiter,
I''m not entirely sure what you are trying to do here, but it sounds
like you want to exit a function before you have reached the end?

You can exit a function at any point with the return(var) statment. For
example if your fundtion returns an integer you can call return(0).

e.g.

int test_fnc(int input)
{
if (input >= 1)
return (1);
else
return(0);
}

After the return statment the function is removed from the stack.
Hope that helps,
Alastair


Alastair写道:
Alastair wrote:
Deiter写道:
Deiter wrote:
状态机和协同程序

goto上的另一个主题:引导我想问......本着
状态的精神机器和协同程序,这个n00b到C想知道是否
setjmp / longjmp是打破常规的唯一方法;离开
函数并重新进入堆栈状态。

我问这个是因为我只是简单地回顾了这些函数
我相信longjmp只会返回一个指定的int。因此我会天真地假设指针会/可能用于返回或改变变量。我想我还记得有关挥发性
限定词的内容。
State Machines and Coroutines

The other thread on goto: Lead me to want to ask... In the spirit of
state machines and coroutines, This n00b to C would like to know if
setjmp/longjmp are the only way to break out of a routine; leave the
function and re-enter the stack state.

I ask this because I''ve only briefly, as yet, reviewed these functions
and I believe longjmp will only return a designated int. Therefore I
would naively assume pointers would/could be used to return or alter
variables. I think I remember something mentioned about volatile
qualifiers being used as well.



嗨Deiter,
我不完全确定你要做什么在这里,但听起来好像你想在到达终点之前退出一个函数?

你可以在任何时候使用return(var)语句退出函数。对于
示例,如果您的基金返回一个整数,您可以调用return(0)。



int test_fnc(int input)
{
if(输入> = 1)
返回(1);

返回(0);
}
返回后的判断该功能从堆栈中删除。
希望有所帮助,
Alastair


Hi Deiter,
I''m not entirely sure what you are trying to do here, but it sounds
like you want to exit a function before you have reached the end?

You can exit a function at any point with the return(var) statment. For
example if your fundtion returns an integer you can call return(0).

e.g.

int test_fnc(int input)
{
if (input >= 1)
return (1);
else
return(0);
}

After the return statment the function is removed from the stack.
Hope that helps,
Alastair




您好,感谢Alastar,但我比我更远了返回。


我相信setjmp允许你放松然后将堆栈放到

中的先前位置,然后调用longjmp。


但我通常对C中的经验如何考虑<感兴趣

高效状态机/协程结构化编程。


谢谢



Hi, thanks Alastar but I''m a bit farther along than returns.

I believe setjmp allows you to "unwind" the stack to a prior position in
the routine when longjmp is then called.

But I''m generally interested in how the experienced in C consider
efficient state machines/coroutine structured programming.

Thanks


>谢谢Alastar但是我回来的时间比我更远。
> Hi, thanks Alastar but I''m a bit farther along than returns.

我相信setjmp可以让你放松。然后,当调用longjmp时,堆栈到了例程中的先前位置。

但我通常对C中的经验如何考虑有效的状态机/协程感兴趣结构化编程。

谢谢

I believe setjmp allows you to "unwind" the stack to a prior position in
the routine when longjmp is then called.

But I''m generally interested in how the experienced in C consider
efficient state machines/coroutine structured programming.

Thanks




嗨Dieter,


嗯...几乎所有我在C中做的是作为状态机的一部分,但是我没有遇到需要使用setjmp / longjmp,我们需要每一点

的效率我们可以获得(在某些情况下)。


我会有兴趣听到其他人说的话......


你有吗您想要实现的一个简单示例?



Hi Dieter,

Hmm... nearly everything I do in C is as part of state mechines, but I
have not come across a need to use setjmp / longjmp, we need every bit
of efficiency that we can get (in some cases).

I''ll be interested to hear what other poeple have to say...

Do you have a simple example of what you are trying to achieve?


这篇关于状态机和协同程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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