Board index » delphi » Division by Zero

Division by Zero

I have Borland Turbo Pasacal 6.

When running a new maths program from within the compliler
there is often an error message such as "Division by zero".

Please tell me in plain english each simple step (mouse
clicks etc) I must take to find the program line on which
the programming error has occurred.

And I shall be for ever grateful.
--
***********************************
Regards from Reg, G4FGQ
For free radio modelling software go to:
http://www.btinternet.com/~g4fgq.regp

***********************************

 

Re:Division by Zero


It is possible, that your processor is too fast for Turbo Pascal. There
is a patch you can download somewhere in the Net to fix that problem, but
unfortunately I can not remember how to find it... sorry.

andreas.

Re:Division by Zero


Quote
Andreas Vo? <voss1...@uni-trier.de> wrote:
> It is possible, that your processor is too fast for Turbo Pascal. There
> is a patch you can download somewhere in the Net to fix that problem, but
> unfortunately I can not remember how to find it... sorry.

If you had read the question more closely, you would have noted that he is
using Turbo Pascal 6, for which this problem does not occur.

Since I don't have a copy of TP 6, I can't answer in the sort of detail
requested. If it has a "Find error" function similar to TP 7's, that would
be best (you'll need to note the address at which the error is reported).
Otherwise I'd suggest single-stepping through the code until the eror
occurs. Under TP 7 this can be done with Debug|Step Into and related
commands; I don't know how TP 6 does it.

--
______________________________________________________________________
     The Scarlet Manuka,      |        Nitpickers' Party motto:
  Pratchett Quoter At Large,  |  "He who guards his lips guards his
 First Prophet of Bonni, is:  |  soul, but he who speaks rashly will
   sa...@maths.uwa.edu.au     |    come to ruin." -- Proverbs 13:3
______________________________|_______________________________________

Re:Division by Zero


Reg,

I'll risk exposing myself to your everlasting gratitude.

Turbo Pascal User's Guide, pg. 231, Compiler Options,
Options/Linker/Map File (detailed): /GD
Hence   tpc.exe  /GD  test.pas

When you get your Division by zero error, note the address where the error
occurrs, then look up test.map to see which line of source code includes
that address.

You don't need a mouse. You do need some DOS skills.

Klaus

Quote
Reg Edwards wrote in message <91plp6$5a...@uranium.btinternet.com>...
>I have Borland Turbo Pasacal 6.

>When running a new maths program from within the compliler
>there is often an error message such as "Division by zero".

>Please tell me in plain english each simple step (mouse
>clicks etc) I must take to find the program line on which
>the programming error has occurred.

>And I shall be for ever grateful.
>--
>***********************************
>Regards from Reg, G4FGQ
>For free radio modelling software go to:
>http://www.btinternet.com/~g4fgq.regp

>***********************************

Re:Division by Zero


Quote
"Reg Edwards" <g4fgq.r...@btinternet.com> wrote in message

news:91plp6$5a3$1@uranium.btinternet.com...

Quote
> I have Borland Turbo Pasacal 6.

> When running a new maths program from within the compliler
> there is often an error message such as "Division by zero".

> Please tell me in plain english each simple step (mouse
> clicks etc) I must take to find the program line on which
> the programming error has occurred.

Sorry, I can't be that exact. But you are running in the IDE. The IDE
should normally put you at the error position when the error occurs.
Since it does not, perhaps the error address is in a unit for which
you do not have source? I would expect the IDE to find the error if
the source is available, even if debug information was not turned on -
all it needs is the address and the linker information.

So how do you find an error address when the IDE fails? Can you get
the error address, by running outside of the IDE? Set the linker
options to give a detailed .MAP file. Set the compiler target to Disk,
compile to a .EXE, then run the program from a DOS window (or just
outside the IDE if you are using plain DOS). You should get an error
message with an address in the form of two 4-digit hexadecimal
numbers, e.g.
  Runtime error 200 at 0005:001C.
The first number, 0005 in this example, is the segment. Each unit is
in a different segment. This error is from a unit QQ which has one
procedure which divides an integer by 0. Now at the start of the .MAP
file there should be a list of units. These are listed under the
headings

 Start  Stop   Length Name               Class

 00000H 00047H 00048H PROGRAM            CODE
 00050H 000B1H 00062H qq                 CODE
 000C0H 00854H 00795H System             CODE
 00860H 00BFFH 003A0H DATA               DATA
 00C00H 04BFFH 04000H STACK              STACK
 04C00H 04C00H 00000H HEAP               HEAP

Now, the Start column is the segment with one trailing 0 (because
segments are given in units of 16 bytes, that's 10 in hex). So the
error at 0005:001C is in the unit starting at 00050, ie unit qq (if we
didn't already know). If you have a detailed map file, with line
number information turned on (you may need to set a compiler option to
get line number info) then you can look down for a line

Line numbers for qq(QQ.PAS) segment qq

followed by line number information. In this case there is
    14 0005:0018    15 0005:0022

so clearly 0005:001C means somewhere in the middle of the
implementation of line 14.

But of course, if you don't have the source for the unit, that doesn't
do you a lot of good. And if the unit was not compiled with line
number information, then the .MAP file won't have this information
either.

Another thing you can do, is step through the program. Use the F8 key
to step over the program, until you come to a procedure where, when
you press F8, the program crashes. Now start again, but this time,
when you get to that procedure, press F7 (step into) instead of F8. Do
the same F8 trick until you find what line of that procedure kills the
program. Then start again, but step into that procedure. When the
program crashes, you can put a breakpoint on the line that did it
(ctrl-F8) so you don't have to step back to that point, but be aware
that the first call of that line might not be the problem - for
example you could call a procedure 20 times with 20 different
parameter values, and then call it with a bad value that causes the
crash. So you can set properties for the breakpoint. After setting the
breakpoint, click on Debug in the menu bar, and then Breakpoints (or
whatever your equivalent is, I'm assuming the TP6 IDE is like the BP7
IDE). Select the breakpoint you just set, and click Edit. You should
be able to set a Condition, and/or a Pass count. Condition is a Pascal
boolean expression, such as
  ((i=123) and (MyColour=Green)) or (Today=Tuesday)
with no semicolon; when the IDE hits the breakpoint it will check the
condition and continue running if the condition is False. Or you can
set a Pass Count to a number, e.g. setting it to 10 will cause the
breakpoint to be ignored the first 9 times it is hit.

With these, you should be able to close in on where the program is
failing. Watch your variables (ctrl-F7) and hopefully you will be able
to make out why the program is failing at that point. Look at the Call
Stack (ctrl-F3) and you may see how the program came to be in this
position. With luck and some scratching of the head you may then
realise what you're doing wrong, and then you can fix it.

Good luck

FP

Re:Division by Zero


JRS:  In article <91plp6$5a...@uranium.btinternet.com> of Wed, 20 Dec
2000 07:05:57 seen in news:comp.lang.pascal.borland, Reg Edwards

Quote
<g4fgq.r...@btinternet.com> wrote:
>I have Borland Turbo Pasacal 6.

>When running a new maths program from within the compliler
>there is often an error message such as "Division by zero".

>Please tell me in plain english each simple step (mouse
>clicks etc) I must take to find the program line on which
>the programming error has occurred.

Firstly, see if it is actually Version 7 (seven) of the system - Help
About will tell you.

If it is, and if the RTE200 message comes at the beginning of any
program using the Crt unit, then EITHER read the mFAQ and the FAQ and
<URL: http://www.merlyn.demon.co.uk/pas-r200.htm> and use Pedt's Crt
unit OR use a slower computer.

Otherwise, see how much output you get before the message, and use that
as a guide.  I "always" put a write-to-screen at the start of a program,
to check that it has started.

Then either add diagnostic write statements, or use the built-in
de{*word*81}. In BP7, that's F4 F7 F8 (see Run menu), and the Debug menu.

Before that, however, check that you have ALL run-time checks and debug
aids turned on.  Options menu, Compiler : R S I C  D L y  v t.

At a guess, you may be dividing by a variable that as yet has no value
assigned.

If TP6 gives something like   Runtime error 200 at 0003:000C   in the
Output window, then, without changing anything else, put that in Search
menu, Find error.  I think this only works, with error 200, for integer
divisions (div); in float-point divisions, the error location is
apparently in a subroutine.

Read the FAQs anyway.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.

Re:Division by Zero


Reg

Having had a similar problem ( data files were not as specified ) my
solution was to place a diagnostic routine just prior to each routine that
contained a divide operation.  This opened a file, wrote a line identifying
the next routine and then close the file.

After a crash the last line of the  file tells you the routine that had a
zero passed to it.

Bernard

Quote
"Reg Edwards" <g4fgq.r...@btinternet.com> wrote in message

news:91plp6$5a3$1@uranium.btinternet.com...
Quote
> I have Borland Turbo Pasacal 6.

> When running a new maths program from within the compliler
> there is often an error message such as "Division by zero".

> Please tell me in plain english each simple step (mouse
> clicks etc) I must take to find the program line on which
> the programming error has occurred.

> And I shall be for ever grateful.
> --
> ***********************************
> Regards from Reg, G4FGQ
> For free radio modelling software go to:
> http://www.btinternet.com/~g4fgq.regp

> ***********************************

Re:Division by Zero


Dear Klaus, tell me what "test.map" is and how to look at
it. In plain english and I'll be even more grateful.
----
Regards from Reg.
http://www.btinternet.com/~g4fgq.regp

***********************************
KlausL wrote .

Quote
> Reg,

> I'll risk exposing myself to your everlasting gratitude.

> Turbo Pascal User's Guide, pg. 231, Compiler Options,
> Options/Linker/Map File (detailed): /GD
> Hence   tpc.exe  /GD  test.pas

> When you get your Division by zero error, note the address
where the error
> occurrs, then look up test.map to see which line of source
code includes
> that address.

> You don't need a mouse. You do need some DOS skills.

> Klaus

> Reg Edwards wrote in message

<91plp6$5a...@uranium.btinternet.com>...

- Show quoted text -

Quote
> >I have Borland Turbo Pasacal 6.

> >When running a new maths program from within the
compliler
> >there is often an error message such as "Division by
zero".

> >Please tell me in plain english each simple step (mouse
> >clicks etc) I must take to find the program line on which
> >the programming error has occurred.

> >And I shall be for ever grateful.
> >--
> >***********************************
> >Regards from Reg, G4FGQ
> >For free radio modelling software go to:
> >http://www.btinternet.com/~g4fgq.regp

> >***********************************

Re:Division by Zero


Reg,

If your source file is called "test.pas" then the command

tpc.exe  /GD  test.pas

will generate a number of files. One of them is called "test.map".
It is a text file that includes the information you originally asked
for.

Klaus

Quote
Reg Edwards wrote in message <91vqsv$o7...@plutonium.btinternet.com>...
>Dear Klaus, tell me what "test.map" is and how to look at
>it. In plain english and I'll be even more grateful.
>----
>Regards from Reg.
>http://www.btinternet.com/~g4fgq.regp

>***********************************
>KlausL wrote .
>> Reg,

>> I'll risk exposing myself to your everlasting gratitude.

>> Turbo Pascal User's Guide, pg. 231, Compiler Options,
>> Options/Linker/Map File (detailed): /GD
>> Hence   tpc.exe  /GD  test.pas

>> When you get your Division by zero error, note the address
>where the error
>> occurrs, then look up test.map to see which line of source
>code includes
>> that address.

>> You don't need a mouse. You do need some DOS skills.

>> Klaus

>> Reg Edwards wrote in message
><91plp6$5a...@uranium.btinternet.com>...
>> >I have Borland Turbo Pasacal 6.

>> >When running a new maths program from within the
>compliler
>> >there is often an error message such as "Division by
>zero".

>> >Please tell me in plain english each simple step (mouse
>> >clicks etc) I must take to find the program line on which
>> >the programming error has occurred.

>> >And I shall be for ever grateful.
>> >--
>> >***********************************
>> >Regards from Reg, G4FGQ
>> >For free radio modelling software go to:
>> >http://www.btinternet.com/~g4fgq.regp

>> >***********************************

Re:Division by Zero


see that adress and copy tpbug.zip on your hard disk, unzip the file and
you'll obtain 4 files that you copy in the directory of turbo pascal in \bin
and division by 0 doesn't work anymore, it was due to crt unit.
http://sigmanet.hypermart.net/archives.htm

Reg Edwards <g4fgq.r...@btinternet.com> a crit dans le message :
91plp6$5a...@uranium.btinternet.com...

Quote
> I have Borland Turbo Pasacal 6.

> When running a new maths program from within the compliler
> there is often an error message such as "Division by zero".

> Please tell me in plain english each simple step (mouse
> clicks etc) I must take to find the program line on which
> the programming error has occurred.

> And I shall be for ever grateful.
> --
> ***********************************
> Regards from Reg, G4FGQ
> For free radio modelling software go to:
> http://www.btinternet.com/~g4fgq.regp

> ***********************************

Other Threads