is this broken or what?

michael.j.knudsen knudsen at cbnewsd.ATT.COM
Thu Feb 1 05:47:19 AEST 1990


One of my "favorite" bugs is
	unsigned	i;
	...
	while(i >= 0) {......}

You can wait a long time for this to terminate....

My question is whether (i >= 0) is ALWAYS TRUE for unsigned i
in all dialects of C (including ANSI) and all hardware architectures,
or am I missing something?

I ask this partly because apparently ANSI has defined "overflow"
to require "change in sign", thus they can say with a straight face
that "unsigned ints never overflow".  I'd like to see their faces
when they try telling that to the hardware (remember that?)
that generates interrupts on overflow.
Seriously, unsigned declarations just control how the compiler
chooses conditional branch instructions when compiling |>| etc.
("higher" versus "greater"), so it's too late to call off
hardware overflow interrupts after a subtraction.

Or does ANSI require that such interrupts be disabled before
executing unsigned comparisons, and re-enabled beofre the next signed
one?
-- 
Mike Knudsen  knudsen at ihlpl.att.com   (708)-713-5134
"Round and round the while() loop goes;
        Whether it stops," Turing says, "no one knows."



More information about the Comp.lang.c mailing list