Interesting.

All of this is toolchain dependent....


On Thu, Mar 24, 2011 at 7:34 AM, Xiaohui Liu <whu...@gmail.com> wrote:

> Hi,
>
> I just tested the following snippet on TelosB, whose output is also listed.
>

You should also include the output of msp430-gcc --version because it is
toolchain
dependent.  I strongly suspect you are running the TinyOS toolchain from the
Stanford
repository which is 3.2.3 without any 430X extensions.


>     int8_t a, b;
>     a = -1;
>     printf("%d\n", a << 1); //-2
>

that one I understand.


>     a = -127;
>     b = a << 1;
>     printf("%d\n", b); //2
>

that one I understand.


>     printf("%d\n", a << 1); //-254
>

I suspect what is actually going on here is a << 1 is indeed producing  a
int8_t result
which is then being promoted to int16_t because of the printf.

The only way to really tell is to look at the generated code.

    b = a >> 1;
>     printf("%d\n", b); //-64
> So the right shift is arithmetic.


Okay.   I'll take a look with the new toolchains and see if it is the same.
  Currently folks are using
3.2.3 which is really really old.

The new toolchain is gcc4 based and there were lots of changes so we'll see
if the shifting changed.

I'll let you know.


> Is constant integer regarded as 16 bit signed int? That's why 'b' produces
> 2 while 'a << 1' -254 because 'a' is promoted to 16 bit signed first.
>
>
>
_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to