develooper Front page | perl.perl5.porters | Postings from July 2003

[perl #23061] Division by zero should be run time error, not compile time

Ed Avis
July 20, 2003 13:56
[perl #23061] Division by zero should be run time error, not compile time
Message ID:
# New Ticket Created by  Ed Avis 
# Please include the string:  [perl #23061]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.26 running under perl 5.008.

[Please enter your report here]
use warnings;
use strict;
use constant N => 0;
if (N == 0) {
print 1 / N;

This fails with 'Illegal division by zero at /home/ed/ttt line 8.',
even though there is an explicit check so that the division never
happens if N is set to zero.

Evaluating constant expressions at compile time is a useful
optimation, but it shouldn't break programs that would otherwise work.

I think the above program worked fine with perl 5.005.  For more
precedent, look at what C does:

#include <stdio.h>
int main(void)
	const int N = 0;
	if (N == 0) exit();
	printf("%d\n", 1 / N);
	return 0;

This is a legal program and the compiler does not complain about the
division by zero (at least, gcc -Wall -O3 does not).  Any error
happens at run time, and only if the code is reached.

[Please do not change anything below this line]

This perlbug was built using Perl 5.00503 - Thu Aug 10 15:31:56 EDT 2000
It is being executed now by  Perl 5.008 - Sat Apr 12 10:55:50 BST 2003.

Site configuration information for perl 5.008:

Configured by tomc at Sat Apr 12 10:55:50 BST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
    osname=linux, osvers=2.2.19-, archname=i686-linux
    uname='linux 2.2.19- #1 sat nov 3 02:42:38 cst 2001 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    cppflags='-fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lbind -lnsl -lgdbm -ldl -lm -lc -lcrypt -lutil
    perllibs=-lbind -lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:

@INC for perl 5.008:

Environment for perl 5.008:
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/bash Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About