www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/05/13/02:57:45

From: calle AT erix DOT ericsson DOT se (Carl Wilhelm Welin)
Date: Thu, 13 May 93 08:08:40 +0200
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Strange division by zero

I have the following little test program "test0.c" on my i486DX/33 AT clone
with 4Mb memory and a Trident 8900 1Mb SVGA card (using MS-DOS 5.0 and
HIMEM.SYS i.e. XMS memory):

	#include <stdio.h>
	int main(argc, argv)
	int argc;
	char *argv[];
	{
	   float result;
	   float atof();
	   result = 100.0 / atof(argv[1]);
	   printf("Result is %f\n", result);
	   return(0);
	}

which I compile with djgcc222:

	C:\>gcc -o test0 test0.c

and run with go32 from djdev109, deliberately trying to divide by zero:

	C:\>go32 test0 0.0
	c:/djgpp/bin/go32.exe version 1.09 Copyright (C) 1991 DJ Delorie
	Result is 100.000000
	C:\>

That is, the "division-by-zero" exception signal from the floating point
processor of the i486DX is completely ignored, and the first argument of
the division is returned as the answer (presumably it remains in the
processor register where the program expects to find the correct result
of the computation). When I compile with "gcc -g -o test0 test0.c" and 
run with debug32.exe from djdev109, I get the same kind of behavior, i.e.
the exception signal is ignored. Is this the intended behavior, or is it
a bug of go32/debug32 version 1.09?

When I run the same example with go32 from djdev108 the program crashes
and I get the printout:

	c:/djgpp/bin/go32.exe version 1.08 Copyright (C) 1991 DJ Delorie
	Exception 117 at eip=10ab
	C:\>

When I run the example with debug32 from djdev108 and step through it with
the "next" command I get a nice little printout about "division-by-zero"
exception signal at the appropriate step, and then I can continue stepping.
Somehow I prefer the behavior of go32/debug32 version 1.08 to the one of
version 1.09, since 1.08 gives me a warning that I have done something wrong.
Opinions?

Carl W. Welin
Ellemtel Telecom Laboratories
Stockholm, Sweden
calle AT eua DOT ericsson DOT se


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019