Significant deficiency in C
Gary M. Samuelson
garys at bunker.UUCP
Tue Oct 7 00:49:05 AEST 1986
In article <1372 at jade.BERKELEY.EDU> mwm at eris.UUCP (Mike Meyer) writes:
>In article <6129 at alice.uUCp> ark at alice.UucP (Andrew Koenig) writes:
>>One would think that for many char operations it is possible for
>>the compiler to figure out that doing it in 8 bits and expanding to
>>16 at the end only if necessary will give the same result as expanding
>>to 16 bits immediately.
>>
>>Can you give us some examples of code that you think would be
>>impossible to get right without changing the rules?
>
>Yes. How about (from a bug report on Lattice C in net.micro.amiga):
>
> char x = 0XFF, y = 2, z ;
>
> z = (x + y) / 2 ;
>
>If you do this in character arithmetic, you get 0 (1/2). If you do it
>as something longer, you get 128.
Unless, of course, char is considered signed, in which case the result
will still be 0.
(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.)
Gary Samuelson
More information about the Comp.lang.c
mailing list