I'm catching up on perl mailing lists... Anyway this thread is the first non-contrived and non-paranoid possible use I've seen for Acme::Landmine On Sun, 2003-07-20 at 16:59, Ed Avis wrote: > On 20 Jul 2003, Kurt Starsinic wrote: > > > What should it do this case? > > > > use constant N => 0; > > exit if N == 0; > > DUMMY: > > print 1 / N; > > eval 'goto DUMMY'; # Or "eval <STDIN>" > > The '1 / 0' should be an error if it is reached in code. The simplest > way to do that is to make it a run-time error. > > (The above program would exit() on the second line.) > > >>#include <stdio.h> > >>int main(void) > >>{ > >> const int N = 0; > >> if (N == 0) exit(); > >> printf("%d\n", 1 / N); > >> return 0; > >>} > > > gcc 3.2.1 complains. It doesn't even have to have -Wall on, just -O. > > True; but it's a warning, not a hard error. Otherwise turning on -O > would break a previously legal program, and that would be a bug in > gcc. > > > If you wanted to code up a patch to avoid folding "1 / N" if > >it's NaN, I probably wouldn't complain. However, I consider it a > >feature that it's a compile time error. > > It does make it rather tricky to generate strings of Perl code and run > them, or to provide tweakable constant parameters which can be > zero. You have to resort to workarounds like stuffing the constant > into a variable just so the compiler won't be able to 'optimize' the > code and break it. > > But without a language specification to consult, I can't give any > hard evidence disagreeing with 'it's not a bug, it's a feature'. I > will try to write a patch. > > Probably 1 / 0 should be turned into an expression that die()s with a > division by zero error - that way it will still be as efficient as > possible ;-). -- David Nicol / If at first you don't succeed, use a bigger hammer. http://gallaghersmash.com