in reply to Buffered, bruised and broken
You are Suffering from Buffering. When you swap your output to file writes, the buffering behavior is swapped as well. You can repair this by making STDIO "hot" by setting the special variable $| to true. The following code behaves as you would expect.
## try.pl ## use strict; use warnings; #use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C'; void foo(int i) { printf("From C: %d\n", i); /* Flush all IO buffers */ fflush(NULL); } END_C $| = 1; for (my $i =0; $i < 10; ++$i) { print "From perl: $i\n"; foo(++$i); }
P.S. You didn't get bit this time, but you should always use strict;. Perhaps that was a transcription error, given that you use warnings;.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Buffered, bruised and broken
by syphilis (Archbishop) on Jan 24, 2009 at 13:58 UTC | |
by ig (Vicar) on Jan 24, 2009 at 18:44 UTC | |
by ikegami (Patriarch) on Jan 24, 2009 at 22:59 UTC | |
by syphilis (Archbishop) on Jan 24, 2009 at 22:25 UTC | |
by ikegami (Patriarch) on Jan 24, 2009 at 22:32 UTC | |
by kennethk (Abbot) on Jan 24, 2009 at 18:30 UTC |