On Tue, 2010-02-23 at 23:37 +0000, Grant Edwards wrote:
> On 2010-02-23, Carl <[email protected]> wrote:
> > On Tue, 2010-02-23 at 23:08 +0000, Grant Edwards wrote:
> >> 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.
> >
> > A short on both my system and 430 is 16 bits. A long on both my
> system
> > and the 430 are both 32 bits. I can inspect the memory with gdb. The
> > problem is the upper 16 bits of y on the 430 are set. Why does it do
> > this?
> >
> > On PC:
> >
> > (gdb) p sizeof(y)
> > $1 = 4
> > (gdb) p /x y
> > $2 = 0x8000
> >
> > On 430:
> >
> > (gdb) p sizeof(y)
> > $1 = 4
> > (gdb) p /x y
> > $2 = 0xffff8000
>
> Unless you provide the code that was run up to that point,
> there's no way to answer your question.
>
> But, I suspect that on the msp430, the value in question was an
> "int" at some point and then got converted to a long.
>
> On the MSP430, that resulted in the value being sign-extended
> when it got converted from 16 to 32 bits. On a PC, an "int"
> and "long" are both 32 bits, so there is no sign extension when
> a value is converted from an int to a long.
Sorry, here is the code for the msp430:
#include <io.h>
int main(void)
{
short x = -32768;
unsigned long y = -x;
LPM0;
}
And same code as my previous posting for the 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);
}
As you can see there is no int type used.
Carl