On 2010-02-23, Carl <[email protected]> wrote:
>
> Ok, I agree not a problem with abs(). But from a C programmer's point of
> view there is a difference in the way the msp430 is handling the
> calculation/conversion. For example from my PC:
>
> #include <stdio.h>
> int main()
> {
> short x = -32768;
> unsigned long y = -x;
> printf("sizeof short =%d, x=%d, y=%lu\n", sizeof(short), x, y);
> }
>
> Output: sizeof short =2, x=-32768, y=32768
>
> While on the msp430 it would give:
>
> Output: sizeof short =2, x=-32768, y=4294934528
>
> If the msp430 was treating the operation as on a short I would
> expect the msp430 y variable to have a value in the range of a
> short as the result.
>
> I'm not sure why there is a difference
The values being passed to printf and then displayed are
"unsigned". On the '430, that's 16 bits. On the PC that's 32
bits.
> and maybe the PC gcc is not doing the right thing.
They're both doing the right thing.
> Do you know where in the C standard it defines the correct
> behavior?
Not off the top of my head.
--
Grant Edwards grante Yow! Did something bad
at happen or am I in a
visi.com drive-in movie??