in reply to Re: [OT]: Flushing XS buffers portably
in thread [OT]: Flushing XS buffers portably

Dammit, derby, you found the escape clause :-)

In real life, foo calls a third party C library function that does use stdio for printing ... something like:
use Inline C => <<'EOC'; #include <mpfr.h> void foo(mpfr_t * x) { mpfr_out_str(*x, .......); } EOC
The Inline::C script that I presented was the closest thing I could think of that would actually depict the problem generically ... but, as I can now see, I stuffed up.

So ... although your response answers the question I asked, it doesn't really address the question I was hoping to be answered ... my fault, not yours.

I guess I'm really after a way of flushing the stdio printf buffer - sort of an stdio way of doing $| = 1; (if such exists).

Btw, I had long wondered about the advantages of using the PerlIO_* routines as recommended in perldoc perlclib (and other places). Your reply provides an excellent demonstration of those "advantages". Thank you.

Cheers,
Rob

Replies are listed 'Best First'.
Re^3: [OT]: Flushing XS buffers portably
by almut (Canon) on Aug 31, 2007 at 14:04 UTC
    I guess I'm really after a way of flushing the stdio printf buffer - sort of an stdio way of doing $| = 1; (if such exists).

    Have you tried fflush(3)?

    (It's not autoflushing, though; you have to call it whenever you want to have the buffers flushed...)

      Have you tried fflush(3)?

      If I literally fflush(3); it segfaults on both winders and linux ... but fflush(stdout); works fine on both platforms. Thanks muchly.

      I guess that's likely to work on other operating systems as well ?

      Cheers,
      Rob

        The '3' is the manual page section ("library calls") where the function is documented... :)   (an old unix convention — typically, I avoid using it for just that reason... sorry I didn't in this case).

        I guess that's likely to work on other operating systems as well ?

        Yes I'd think so, it's a pretty standard library call (ANSI C - X3.159-1989, the man page says).