Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A quirky bug

Status
Not open for further replies.

rotovegasBoy

Programmer
Sep 16, 1999
88
NZ
I've written two programs to simulate a transaction lookaside buffer in a sparc 4 (any sort of processor uses the same concepts the just don't call it a t.l.b. :) The programs get from a pipe a stack trace and simulate vairous replacement algorithms.&nbsp;&nbsp;The first program works fine.&nbsp;&nbsp;The second has a small (weel kinda big) bug it will slip into an infinite loop. If I pipe the output through the unix &quot;head&quot; command it doesnt enter the infinite loop.<br>I'm using the command<br><br>while(fscanf(stdin, &quot;%d %x&quot;, &i, &v)==2){<br>//stuff here<br>}<br><br>in both programs i can't quite see why one is looping infinitely and one is not.&nbsp;&nbsp;the diference between the two is that the second reads ahead and puts the v hex number into an array, when the array is full it simulates a best case scenario with the array. Any idea why this is looping without the use of &quot;head&quot;?
 
It would be easier to trace your problem if you could elaborate a bit. Because by just looking your while loop , it will loop till fscanf fails to get 2 inputs . So it must be getting 2 inputs all the time that is why the loop is infinite (as per the information given above).&nbsp;&nbsp;One thing you do , At the last of the while loop just include fflush(stdin);&nbsp;&nbsp;and let us know , if it helps<br><br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A>
 
Yeah i thought <FONT FACE=monospace>fflush()</font> may help right after i posted the message.&nbsp;&nbsp;Will that flush the whole of stdin or just the part i've read?
 
I left the program running overnight and it did finish :)<br>I guess this proves Turing right. This program was just 100 times slower than the other making me believe that it was looping infinitely.&nbsp;&nbsp;Thanx for the help Siddhartha.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top