On Monday 11 January 2010 03:38:53 Larry Finger wrote:
> Yes, my fault. The specs are now corrected so that these statements are
> 
> ((s8)((s[1] >> 8) & 0x3F) << 2) >> 2
> 
> I think that is right.

No it is not.

You need to do this:
(s8)(((s[1] >> 8) & 0x3F) << 2) >> 2

Alternatively add another pair of parenthesis to make it clearer:

((s8)(((s[1] >> 8) & 0x3F) << 2)) >> 2

This basically shifts left unsigned and then shifts right _arithmetically_.
In your example, the compiler will optimize both shifts away (it may actually
also optimize the shifts in my case, but the sign extension will persist.

Just try it and you'll see:

m...@homer:~$ cat t.c
#include <stdio.h>
#include <stdint.h>

int main()
{
        int8_t s0;
        int8_t s1;
        uint8_t u;

        u = 0x3D;

        s0 = ((int8_t)(u & 0x3F) << 2) >> 2;
        s1 = ((int8_t)((u & 0x3F) << 2)) >> 2;

        printf("%d %d\n", s0, s1);
}
m...@homer:~$ gcc -o t t.c
m...@homer:~$ ./t
61 -3


-- 
Greetings, Michael.
_______________________________________________
Bcm43xx-dev mailing list
Bcm43xx-dev@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/bcm43xx-dev

Reply via email to