syphilis has asked for the wisdom of the Perl Monks concerning the following question:
There's no problem with that - it outputs (as I expect):## try.pl ## 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 for ($i =0; $i < 10; ++$i) { print "From perl: $i\n"; foo(++$i); }
But when (with perl-5.10.0, both Linux and Windows) I run the script as perl try.pl >out.txt I find that out.txt contains:From perl: 0 From C: 1 From perl: 2 From C: 3 From perl: 4 From C: 5 From perl: 6 From C: 7 From perl: 8 From C: 9
I don't understand why the output has changed - I expected the flushing of the buffers to take care of things for me ... but it obviously didn't. Can anyone enlighten me ?From C: 1 From C: 3 From C: 5 From C: 7 From C: 9 From perl: 0 From perl: 2 From perl: 4 From perl: 6 From perl: 8
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Buffered, bruised and broken
by kennethk (Abbot) on Jan 24, 2009 at 12:39 UTC | |
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 |