binary constants (??)
Dr A. N. Walker
anw at maths.nott.ac.uk
Tue Dec 5 02:02:17 AEST 1989
In article <1989Nov29.164913.1794 at utzoo.uucp> henry at utzoo.uucp (Henry
Spencer) writes:
>In article <20989 at mimsy.umd.edu> chris at mimsy.umd.edu (Chris Torek) writes:
>> [proposes] <base>r<text>, 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 at maths.nott.ac.uk
More information about the Comp.lang.c
mailing list