Re: C and side-effects

From: Anton Altaparmakov (aia21@cam.ac.uk)
Date: Thu May 04 2000 - 05:54:46 EST


At 10:50 04/05/2000, George Anzinger wrote:
> I wrote:
>
>c = (c - d)>>n + d;
>
>and tested for values of 0 < c < 40, 1 < d < 40 and 0 < n < 80.
>
>Turns out that gcc (and the hardware) tend to give unexpected results
>for n>32. I think the shift is done modulo 32. What does the standard
>have to say about this?

Aren't you thinking of: c = ((c - d) >> n) + d ? That would evaluate as d-1
for n > 32 but what you said is actually:
What you write would evaluate as: c = (c - d) >> (n + d) which obviously
does something else...

This is according to K&R and a quick test (using gcc!).

Anton

--

"Education is what remains after one has forgotten everything he learned in school." - Albert Einstein

-- Anton Altaparmakov Voice: 01223-333541(lab) / 07712-632205(mobile) Christ's College eMail: AntonA@bigfoot.com Cambridge CB2 3BU ICQ: 8561279 United Kingdom WWW: http://www-stu.christs.cam.ac.uk/~aia21/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun May 07 2000 - 21:00:14 EST