Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!hsi!stpstn!lerman From: lerman@stpstn.UUCP (Ken Lerman) Newsgroups: comp.lang.c Subject: Re: compiler detecting divide by zero Message-ID: <5857@stpstn.UUCP> Date: 27 Nov 90 15:21:42 GMT References: <36233@cup.portal.com> Reply-To: lerman@stpstn.UUCP (Ken Lerman) Organization: The Stepstone Corporation, Sandy Hook, CT 06482 Lines: 58 In article <36233@cup.portal.com> ts@cup.portal.com (Tim W Smith) writes: ->For obscure reasons that I won't go into, I wanted a divide ->by zero in a program. I was compiling on SCO Unix System V/386 ->relase 2.2 (I think...) with whatever C compiler comes with ->this version of Unix. -> ->I tried the obvious: -> -> int i, j; -> -> i = 1; -> j = 0; -> i/=j; -> ->The compiler caught this. Grrr. Next I tried: -> -> i = 1; -> j = 1; -> i -= 1; -> j/=i; -> ->It still caught it. Double grrr! -> ->Next try: -> -> int i, j, *p; -> -> i = 1; -> j = 1; -> p = &i; -> j /= *p - 1; -> ->It still caught it! -> ->This one got past it: -> -> j = 5; -> for ( i = 0; i < 5; i++ ) -> j--; -> i /= j; -> ->After the previous try, I was a bit surprised that it didn't ->figure out this one! -> -> Tim Smith I haven't tried it, but I'll bet that: int divide(int a, int b){ return a/b; } will cause your divide error when called by: x = divide(1,0); Of course, if your compiler is brilliant, you might have to put the function divide in a separate file. :-) Ken