On Tue, Mar 01, 2005 at 11:43:31AM +1100, Andrew Savige wrote: > running this Perl program: > > use strict; > sub div_by_zero { exec("./a.out $_[0]"); die "should not be here" } > defined(my $pid = fork()) or die "fork: $!"; > if ($pid == 0) { > warn "child, my pid $$\n"; > div_by_zero(0); # sig 8 > # div_by_zero(); # sig 11 > exit; > } > warn "parent, my pid $$\n"; > waitpid($pid, 0); > my $rv = $? >> 8; > my $sig = $? & 127; > warn "$$: rv=$rv sig=$sig\n"; > > produces: > > parent, my pid 12091 > child, my pid 12092 > 12091: rv=0 sig=8 > > Replacing div_by_zero() above with: > > sub div_by_zero { 5 / shift } > > produced: > > parent, my pid 12133 > child, my pid 12134 > Illegal division by zero at g2.pl line 2. > 12133: rv=255 sig=0 >
This is not related to the original topic, but I've always wondered this: In math a number divided by 0 is "undefined". Why is it that in a language which has an undefined value does the interpreter poop out rather than just having the intuitively obvious behavior of returning undef? Is that really by design, or just a legacy quirk they're afraid to fix? Austin