compiler detecting divide by zero
Tim W Smith
ts at cup.portal.com
Mon Nov 26 21:46:48 AEST 1990
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
More information about the Comp.lang.c
mailing list