jeudi 2 juillet 2015

printf() without '\n' doesn't work in libev

Post the code first:

#define EV_STANDALONE 1
#include <stdio.h>
#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;
}

Strange thing happened while running: although the printf("hello, world."); was in the first place in main function, but it didn't work. But if I use printf("hello, world\n"); instead, things worked fine. Further more, I changed printf("hello, world"); instead of puts("hello, world");, it also worked. So what on earth did libev do to the io? Why "\n" matters?

Aucun commentaire:

Enregistrer un commentaire