syphilis has asked for the wisdom of the Perl Monks concerning the following question:
The C file (mylib.c):#include <stdio.h> void my_puts(FILE*);
Now, build the library (libmylib.a):#include <stdio.h> void my_puts(FILE * stream) { fputs("hello from libmylib", stream); }
The perl script that accesses the function in libmylib.a:C:\_32\C>gcc -c mylib.c C:\_32\C>ar cru libmylib.a mylib.o
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.ause 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"; }
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 libmylib hello from perl hello from libmylib hello from perl hello from libmylib 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.hello from libmylib hello from perl hello from libmylibhello from libmylibhello from libmylib hello from perl hello from perl hello from perl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Really, really suffering from buffering
by shmem (Chancellor) on Nov 19, 2007 at 14:11 UTC | |
by syphilis (Archbishop) on Nov 19, 2007 at 22:58 UTC | |
by shmem (Chancellor) on Nov 19, 2007 at 23:15 UTC | |
by syphilis (Archbishop) on Nov 20, 2007 at 00:14 UTC | |
by BrowserUk (Patriarch) on Nov 20, 2007 at 03:05 UTC | |
| |
|
Re: Really, really suffering from buffering
by oha (Friar) on Nov 19, 2007 at 13:55 UTC |