Hi,

The C header file (mylib.h):
#include <stdio.h> void my_puts(FILE*);
The C file (mylib.c):
#include <stdio.h> void my_puts(FILE * stream) { fputs("hello from libmylib", stream); }
Now, build the library (libmylib.a):
C:\_32\C>gcc -c mylib.c C:\_32\C>ar cru libmylib.a mylib.o
The perl script that accesses the function in libmylib.a:
use warnings; use strict; use Inline C => Config => INC => '-IC:/_32/C', LIBS => '-LC:/_32/C -lmylib', BUILD_NOISY => 1; use Inline C => <<'EOC'; #include <mylib.h> void foo(FILE * x) { my_puts(x); fflush(x); } EOC $| = 1; for(1 .. 2) { foo(*stdout); print "\nhello from perl\n"; } for(1 .. 2) { foo(*stderr); print "\nhello from perl\n"; }
Ok ... so I've got this library (libmylib.a) that was built using mylib.h and mylib.c. For the purposes of this exercise, that (3rd party) library is to be considered non-modifiable. Of course, if it's doing something sinful, please let me know. And I've got an Inline::C script that's accessing the one and only function that's in libmylib.a

As it stands, the script outputs (on Win32, perl 5.8.8):
hello from libmylib hello from perl hello from libmylib hello from perl hello from libmylib hello from perl hello from libmylib hello from perl
That's all well and good, and the exact output I'm wanting to see. But if I comment out the line that turns the autoflush on I get the following garbled output:
hello from libmylib hello from perl hello from libmylibhello from libmylibhello from libmylib hello from perl hello from perl hello from perl
I simply do not see why the output should vary in any way, dependent upon whether autoflush is on or off. As I understand it, perl's autoflush will have no effect on the C buffers ... and, since the perl print() statements terminate with a "\n", autoflush should have no effect on the perl buffers either.

I guess I'm overlooking something ... but what ?

Cheers,
Rob

In reply to Really, really suffering from buffering by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.