Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Inline::C output with printf problem

by Cine (Friar)
on Jul 04, 2003 at 01:40 UTC ( [id://271354]=perlquestion: print w/replies, xml ) Need Help??

Cine has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to print a few lines from the C-part of my program, but it seems that there is some limit as to how much I can print? Can Anyone tell me why? Using simple trivial code, called a few hundred times:
void printit() { int i; printf(buf,"%d ",perm); for(i = 0; i < talks; i++) printf("%d ",res_a[i]); printf("\n"); }
If I run this in the shell it works fine (I get a ton of output)...
If I pipe it trough wc I get:
$perl test.pl | wc 46 2859 8192
I then tried to call the output function twice for every time i would call it othervise and puf:
$ perl test.pl | wc 113 7164 20480
As in I get the full output (twice) Why the sudden succes?!?

Ok so I must hit some magic barrier, but I cant find any other who have the same problem or any kind of documentation that would explain it. If I add an extra printf("                                                                           \n")(lots of spaces) it works.
As a second choice I then tried to call a perlfunction which print, but that keeps segfaulting?
void printit() { Inline_Stack_Vars; Inline_Stack_Reset; int i; int howmuch; char buf[1000]; howmuch = sprintf(buf,"%d ",perm); for(i = 0; i < talks; i++) { howmuch+=sprintf(buf+howmuch,"%d ",res_a[i]); } buf[howmuch-1] = '\n'; Inline_Stack_Push(newSVpvf("%s",buf)); Inline_Stack_Done; perl_call_pv("main::printme",0); Inline_Stack_Void; } In Perl: sub printme { print for $_[0]; }


T I M T O W T D I

Replies are listed 'Best First'.
Re: Inline::C output with printf problem
by sgifford (Prior) on Jul 04, 2003 at 04:33 UTC
    Sounds like stdio buffering. What if you add
    fflush(stdout);
    to the end of your C code?
      Already tried that, and sync and fsync.

      T I M T O W T D I

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://271354]
Approved by Enlil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found