Tag: libev

在C代码中使用boost :: bind(),它会起作用吗?

我可以在C代码中使用boost::bind(mycallback, this, _1, _2)吗? 更新 简短的回答是不 ,boost bind不会返回一个函数指针,它可以在C代码中调用,但是一个函子 (带有overloaded ()运算符的C ++对象)请参见下面的答案。

Libev,如何将参数传递给相关的回调

我陷入了在libev中传递争论的局面。 通常,libev在类似* receive_callback *的函数中接收包,这没关系,但实际上,我们需要根据收到的包调度相对* write_callback *来处理特定的作业。 例如: S_RECV_MSG* pstRecvMsg = (S_RECV_MSG*) recv_buff; switch(pstRecvMsg->wMsgType) { case 1: ev_io_init(w, write_callback1, w->fd, EV_WRITE); break; case 2: ev_io_init(w, write_callback2, w->fd, EV_WRITE); break; case 3: // ……. } 我的问题是,如果write_callbackX还必须读取write_callbackX的特定内容,我们如何将recv_buff参数传递给callbackX? 我们必须承担全球变量的负担和丑陋吗?

为什么在宏定义中使用do {} while(0)?

可能重复: 为什么在C / C ++宏中有时会出现无意义的do / while和if / else语句? 我遇到了如下代码: #define ev_io_init(ev,cb,fd,events) \ do { \ ev_init ((ev), (cb)); \ ev_io_set ((ev),(fd),(events)); \ } while (0) 我想知道为什么作者在这里使用do { } while (0) 。 这有什么不同吗? #define ev_io_init(ev,cb,fd,events) { \ ev_init ((ev), (cb)); \ ev_io_set ((ev),(fd),(events)); \ } BTW:代码来自libev,ev_local.h

没有’\ n’的printf()在libev 中不起作用

首先发布代码: #define EV_STANDALONE 1 #include #include “ev.c” ev_timer timeout_watcher; struct ev_loop* loop; static void timeout_cb (EV_P_ ev_timer *w, int revents) { // puts(“timeout”); printf(“timeout”); ev_timer_again(loop, w); } int main (void) { printf(“hello, world.”); loop = EV_DEFAULT; ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); timeout_watcher.repeat = 2.0; ev_timer_start (loop, &timeout_watcher); ev_run (loop, 0); return 0; } 跑步时发生了奇怪的事情:虽然是printf(“hello, world.”); […]