使用setjmp [英] using setjmp

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

问题描述

当调用setjmp时,如果setjmp只返回0或非零,那么if语句如何计算为true或false



struct pcb {

void *(* start_routine)(void *);

void * arg;

jmp_buf state;

int stack [1024 ];

};

struct pcb * pcb_pointer;

pcb_pointer =(struct pcb *)malloc(sizeof(struct pcb));

if(setjmp(pcb_pointer-> state)){

current-> start_routine(current-> arg);

printf( Thread returns\\\
);

退出(0);

}

When setjmp is called how can the if statement evaluate to true or false
when setjmp only returns 0 or non-zero?
struct pcb {
void *(*start_routine) (void *);
void *arg;
jmp_buf state;
int stack[1024];
};
struct pcb *pcb_pointer;
pcb_pointer = (struct pcb *) malloc(sizeof(struct pcb));
if(setjmp(pcb_pointer->state)) {
current->start_routine(current->arg);
printf("Thread returned\n");
exit(0);
}

推荐答案

>当调用setjmp时,如果setjmp只返回0或非零,那么if语句如何计算为true或false
>When setjmp is called how can the if statement evaluate to true or false




C89中没有真或假。 if语句执行then条款

(即使没有然后关键字)如果条件评估为

非零。


虽然C99有真假,但这与if语句无关。


Gordon L. Burditt



There is no true or false in C89. if statements execute the "then" clause
(even though there''s no "then" keyword) if the condition evaluates to
non-zero.

While C99 has true and false, this has nothing to do with if statements.

Gordon L. Burditt


In文章< d1 ********** @ news.net.uni-c.dk> ;, JS< dsa。@ asdf.com>写道:
In article <d1**********@news.net.uni-c.dk>, JS <dsa.@asdf.com> wrote:
当调用setjmp时,if语句如何评估为true或false
当setjmp只返回0或非零时?


喝咖啡,到户外,坐在一棵树下(或者,如果天气没有合作,至少可以离开电脑),并且

考虑真/假和非零/零之间的差异,并且你将获得启示。

dave


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca 这些天克里姆林宫有一位母亲?
When setjmp is called how can the if statement evaluate to true or false
when setjmp only returns 0 or non-zero?
Have a coffee, go outside, and sit under a tree (or, if the weather
fails to be cooperative, at least get away from the computer), and
contemplate the difference between true/false and nonzero/zero, and you
will be enlightened.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.caThe Kremlin has a mother these days?



经过fflush(stdin)后,最终可能会有三位母亲。

--Joona I Palaste和Gordon Burditt在comp.lang.c


After a fflush(stdin), it might end up having three mothers.
--Joona I Palaste and Gordon Burditt in comp.lang.c




" Dave Vandervies" < DJ ****** @ csclub.uwaterloo.ca> skrev i en meddelelse

新闻:d1 ********** @ rumours.uwaterloo.ca ...

"Dave Vandervies" <dj******@csclub.uwaterloo.ca> skrev i en meddelelse
news:d1**********@rumours.uwaterloo.ca...
文章< d1 *** *******@news.net.uni-c.dk> ;, JS< dsa。@ asdf.com>写道:
In article <d1**********@news.net.uni-c.dk>, JS <dsa.@asdf.com> wrote:
当调用setjmp时,if语句如何计算为true或false
当setjmp只返回0或非零时?
When setjmp is called how can the if statement evaluate to true or false
when setjmp only returns 0 or non-zero?



喝咖啡,到户外,坐在树下(或者,如果天气不合作,至少离开电脑),并考虑真/假与非零之间的区别/零,你将开悟。



Have a coffee, go outside, and sit under a tree (or, if the weather
fails to be cooperative, at least get away from the computer), and
contemplate the difference between true/false and nonzero/zero, and you
will be enlightened.



我只有Java经验,还没有找到任何有关这个

定义的K& R.


Well I have only Java experience and not yet found anything about this
definition in K&R.


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

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