Significant deficiency in C

Guy Harris guy at sun.uucp
Tue Oct 7 06:37:11 AEST 1986


> (In any event, I am not sure that a 'bug report' is a valid source for
> the kind of example Mr. Koenig is looking for.  Fix the bug, and then
> it may be possible to get it right without changing the rules.)

The fact that the string "bug report" appeared there is irrelevant; it
connotes nothing.  This is not a problem with a particular C implementation.
The bug report merely indicates that the problem exists if a C
implementation doesn't follow the rules in question.  Presumably, they were
trying to be "clever" and evaluate the expression in question in 8-bit
arithmetic.

Unfortunately, this *is* one of the cases where you can't do it using 8-bit
arithmetic without changing the rules; in this case, 8-bit arithmetic is
inequivalent to 16-bit arithmetic, and if "int"s are 16 bits (as they
presumably are in this case), the C language requires that the results be
those produced by 16-bit arithmetic.

You can fix the bug by changing the code to use 16-bit arithmetic, in which
case you "get it right" in the sense of giving the right answer but not in
the sense of using 8-bit arithmetic.  You can also "fix" the bug by changing
the rules.  You can't get it right without changing the rules just fixing the
bug; the problem with the rules is not caused by the presence of a bug!
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list