Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!bionet!ames!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: compiler detecting divide by zero Message-ID: <28079@mimsy.umd.edu> Date: 29 Nov 90 08:22:50 GMT References: <36233@cup.portal.com> <5857@stpstn.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 26 In article <5857@stpstn.UUCP> lerman@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@cs.umd.edu Path: uunet!mimsy!chris