Significant deficiency in C

Mike Meyer mwm at eris.berkeley.edu
Thu Oct 2 21:54:08 AEST 1986


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.

Of course, whether or not is is "right" is open to question.

	<mike



More information about the Comp.lang.c mailing list