Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!mcsun!ukc!kl-cs!nott-cs!piaggio!anw From: anw@maths.nott.ac.uk (Dr A. N. Walker) Newsgroups: comp.lang.c Subject: Re: binary constants (??) Message-ID: <1989Dec4.150217.4743@maths.nott.ac.uk> Date: 4 Dec 89 15:02:17 GMT References: <305@frf.omron.co.jp> <20830@mimsy.umd.edu> <20989@mimsy.umd.edu> <1989Nov29.164913.1794@utzoo.uucp> Reply-To: anw@maths.nott.ac.uk (Dr A. N. Walker) Organization: Maths Dept., Nott'm Univ., UK. Lines: 28 In article <1989Nov29.164913.1794@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: >In article <20989@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes: >> [proposes] r, 2r11001 = 8r31 = 25 = 16r19. > [introduces] a new class of subtle errors. (How many programs would >notice if 16r19 was mistyped as 15r19? Or 19r16?) Many moons ago, when my students were writing their programs in a sane language such as Chris suggests, it took me *ages* to spot the bug in [re-written in the D or P idiom!]: int a[20]; for (r = 1; r <= 10; r++) a[2r-1] = r; /* Bzzt! Core dropped! Subscript out of bounds! */ Well, r runs from 1 to 10, so 2r-1 runs from 1 to 19, so that should be OK. You used the same array name, didn't you? No mis-typings? Semi-colons all in the right place. Hmm. Umm. Shouldn't there be a * between 2 and r? I'm surprised the compiler accepted that, quite neat getting implicit multiplication. CLANG! 2r-1 means -1 in binary. (Actually, it should still be a syntax error, but one can see why a compiler might allow it.) -- Andy Walker, Maths Dept., Nott'm Univ., UK. anw@maths.nott.ac.uk