compiler detecting divide by zero
Chris Torek
chris at mimsy.umd.edu
Thu Nov 29 19:22:50 AEST 1990
In article <5857 at stpstn.UUCP> lerman at stpstn.UUCP (Ken Lerman) writes:
>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. :-)
Even that is unlikely to help for long. (You can expect better IBM PC
compilers to do cross-module optimization within 5 years. [I actually
expect it sooner than this. MIPS and Sun already do it.])
Here is something that *will* (must) work:
const volatile int zero = 0;
int exception = 1 / zero;
A compiler cannot assume that a `const volatile int' has any particular
value. For instance:
extern const volatile int clock; /* mapped by linker to clock */
might tell you the current time in seconds since the machine was booted.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list