Daemon News Ezine BSD News BSD Mall BSD Support Forum BSD Advocacy BSD Updates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



Maybe one of out C standards people can define when the conversion
is defined to occur, so we can get a real ruling.

Note that:

int main(void)
{
        unsigned char i = 127;
        printf("%d\n", (char)((i << 1) / 2));
        return 0;
}

...yields 127 on gcc 2.95, so it's definitely order of conversion
being totally screwed by gcc 3.1.

Basically, it's assuming commutability where it's not present.


> In any case, this behavior makes moused(8) return a stupid value of
> 127 when you roll the mouse wheel up under ps/2-sysmouse-intellimouse
> protocol.  Attached is a patch that makes the whole expression look
> more logical and works around the above behavior at the same time.

[ ... ]

> -           act->dz = ((char)(pBuf[5] << 1) + (char)(pBuf[6] << 1))/2;
> +           act->dz = ((char)(pBuf[5] << 1) + (char)(pBuf[6] << 1)) >> 1;

This is *soooooooooo* counter intuitive that it's evil!

-- Terry

To Unsubscribe: send mail to majordomo@xxxxxxxxxxx
with "unsubscribe freebsd-current" in the body of the message