February 22nd, 2007, 09:16 AM
Problem with pascal program
Hi 2 all,
I have a problem with the attached program. Here is a sample input
and ... the program hangs. I think the problem is the high value of B=, because if I input B=100 - the program finished normal, except with one (other) problem - the values of Dsr - they're too high. I translated this program from C to pascal. The compiled C exe is running normaly - I can't find the problem in pascal.
February 22nd, 2007, 03:42 PM
Wow.. That is really hard code to follow. Nevermind.. I see that you have a user variable that you are calling B, and then you have a variable in the program called B that is used as a counter.
You take the user Input of what B is in the function inputlink as N. N is then assigned to M. Absolutely horrible variable names and pretty difficult to follow the code. Especially considering that you have a user input called B that has nothing to do with what B is in the program.
I'd suggest you put some pauses in and tie it to a space bar press. This way you can step through the code in individual sections to find out where it is hanging.
You also seem to switch back and forth from Real, longint, and int without any rhyme or reason that I can see. Why do you change the variable type so much?
Last edited by mohaughn; February 22nd, 2007 at 03:49 PM.
February 22nd, 2007, 03:51 PM
The c code isn't mine. A friend gave it to me to translate it to pascal - i just followed the c code and wrote it in pascal. The program hangs when:
"ProbabilityOfLoss:=calculation;" in the cycle and sometimes it shows 4-5 results, sometimes - 7-8 and hangs.
February 22nd, 2007, 05:01 PM
OK.. So put some pauses in the function calculation and see where it is hanging. You can also write out the contents of the variables before you do the calculations to see if a value is exceeding the size limits of your variables.
You have global variables and local variables all over the place and you switch back and forth for what appears to be no good reason.
For instance, T1, you have it defined as a global variable. But you only use it in the function calculation. Why not just define it as a local variable to that function? "Tim" is another one, you only use it in the procedure test. And you have "F" defined twice. Once as a global text variable and again as a local real.
February 22nd, 2007, 06:07 PM
I trace and Step-over it, but all I found is that when I input high value for B the program hangs after some results and the CPU is on 100%. For high value I mean for example 100000. When I input 10000 - there is no problem.
February 22nd, 2007, 09:20 PM
If your CPU is spiking to 100% either you have a very intensive algorithm or you have a run-away loop...
What you'll have to do is go to each function, minimally, and have it output that that function is being called, and you may even have to periodically in the function, output that you are at a certain place...
Do this enough and you will be able to see where in the algorithm it is getting hung up and that should hopefully provide some insight into what is going wrong...
Sorry I tried looking at it, but its some kind of sloppy and I couldn't follow it very easily (and after some failed attempts to make it work in gcc, I decided to just post some generic debugging advice) ...
I'm also assuming that this CPU spike doesn't occur for the same input in the C version?
I'm suspecting that if it works for a small value but not a larger one, you either have an overflow situation (where the value is actually rolling over and causing a loop to not terminate, ie, because the value being returned is too large for the typecast) or you have an inefficient algorithm that doesn't scale to larger values very well...
Hope that is at least somewhat helpful...
There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.
(Merovingian - Matrix Reloaded)
February 23rd, 2007, 05:50 AM
Here are the exe-s.
And yes, you are right - the c version is working well.
February 23rd, 2007, 11:10 PM
My god, that's more obfuscated than code from the OCCC.
By The Texan in forum Operating Systems
Last Post: June 22nd, 2006, 08:04 PM
By FlamingRain in forum Other Tutorials Forum
Last Post: December 25th, 2003, 04:34 AM
By SpydaByte in forum AntiOnline's General Chit Chat
Last Post: January 20th, 2003, 09:55 PM
By zepherin in forum Other Tutorials Forum
Last Post: July 6th, 2002, 10:09 AM
By Noble Hamlet in forum AntiOnline's General Chit Chat
Last Post: March 17th, 2002, 08:38 AM