c事件处理 - 如何? [英] c event handling - how?

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

问题描述



如何生成事件并由处理程序处理?我知道

如何在C ++或Java中完成它但我不知道如何在C中完成它。什么

是写一个函数的最佳方法一个函数

指针,一个指向用户数据的指针(它是什么?)然后我在某个事件发生时通知它




我是C的新手,顺便说一句:-)


非常感谢你的帮助。

解决方案

ph******@myway.com (Phui Hock)写在

news:a9 ************************** @ posting.google.c om:


如何生成事件并由处理程序处理?我知道如何用C ++或Java做,但我不知道如何在C中做到这一点。
是编写一个函数的最佳方法,它将采用一个函数指针,指向用户数据的指针(它是什么?)然后我在某个事件发生时通知它




你的意思是回电话?我不认为你可以在C.没有线程,

interrtups,或C中的任务。你可以看看是否感兴趣setjmp / longjmp()

但我怀疑标准C会让你做你想做的事情而不用

特定于平台的扩展(这里是偏离主题的)。


- -

- 马克 - >

-


Mark A. Odell写道:
< blockquote class =post_quotes> ph******@myway.com (Phui Hock)在
新闻:a9 ************************** @ posting.google.c om:


如何生成事件并由处理程序处理?我知道如何用C ++或Java做,但我不知道如何在C中做到这一点。
是编写一个函数的最佳方法,它将采用一个函数指针,指向用户数据的指针(它是什么?)然后我在某个事件发生时通知它

你的意思是回电?我不认为你可以在C。




嗯,你可以。

没有线程,


正确

interrtups,


排序错误。硬件级别中断不是这样支持的,而是支持中断(作为一般概念)/支持。

或C中的任务。你可以看看setjmp / longjmp()是否感兴趣
但我怀疑标准C将允许你做你想要的而没有特定于平台的扩展(这里是偏离主题)。




请参阅标准中的signal()和raise()函数以及signal.h


-

Lew Pitcher,IT顾问,应用程序架构

企业技术解决方案,道明银行金融集团


(此处表达的意见是我自己的,不是我的雇主' 's)


Mark A. Odell写道:

ph ****** @ myway.com (Phui Hock)在
新闻中写道:a9 **************** **********@posting.google.c om:


如何生成e发泄并由处理程序处理?我知道如何用C ++或Java做,但我不知道如何在C中做到这一点。
是编写一个函数的最佳方法,它将采用一个函数指针,指向用户数据的指针(它是什么?)然后我在某个事件发生时通知它

你的意思是回电?



OP要求的内容包括但不限于回调。

我认为你不能用C语言。




做什么?回调?是的你可以。看看(标准)qsort()

函数。它需要一个回调函数作为lsat参数。


(剪辑)


布鲁诺


Hi,
How do I generate an event and got it handled by a handler? I know
how to do it in C++ or Java but I got no idea how to do it in C. What
is the best approach to write a function that will take a function
pointer, a pointer to user data (what is it?) and then I notify it
when a certain event happens?

I''m new to C, btw :-)

Thanks a lot for helping.

解决方案

ph******@myway.com (Phui Hock) wrote in
news:a9**************************@posting.google.c om:

Hi,
How do I generate an event and got it handled by a handler? I know
how to do it in C++ or Java but I got no idea how to do it in C. What
is the best approach to write a function that will take a function
pointer, a pointer to user data (what is it?) and then I notify it
when a certain event happens?



You mean call back? I don''t think that you can in C. There are no threads,
interrtups, or tasks in C. You can see if setjmp/longjmp() are of interest
but I doubt standard C will allow you to do what you want without
platform-specific extensions (which are off-topic here).

--
- Mark ->
--


Mark A. Odell wrote:

ph******@myway.com (Phui Hock) wrote in
news:a9**************************@posting.google.c om:

Hi,
How do I generate an event and got it handled by a handler? I know
how to do it in C++ or Java but I got no idea how to do it in C. What
is the best approach to write a function that will take a function
pointer, a pointer to user data (what is it?) and then I notify it
when a certain event happens?

You mean call back? I don''t think that you can in C.



Well, you can.
There are no threads,
Correct
interrtups,
Sort of wrong. Hardware level interrupts aren''t supported as such, but an
abstraction of interrupts (as a general concept) /is/ supported.
or tasks in C. You can see if setjmp/longjmp() are of interest
but I doubt standard C will allow you to do what you want without
platform-specific extensions (which are off-topic here).



See the signal() and raise() functions in the Standard, along with signal.h

--
Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer''s)


Mark A. Odell wrote:

ph******@myway.com (Phui Hock) wrote in
news:a9**************************@posting.google.c om:

Hi,
How do I generate an event and got it handled by a handler? I know
how to do it in C++ or Java but I got no idea how to do it in C. What
is the best approach to write a function that will take a function
pointer, a pointer to user data (what is it?) and then I notify it
when a certain event happens?

You mean call back?



What the OP asks for include, but is not restricted to, callbacks.
I don''t think that you can in C.



Do what ? callbacks ? yes you can. Have a look at the (standard) qsort()
function. It takes a callback function as lsat argument.

(snip)

Bruno


这篇关于c事件处理 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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