[Tinyos-help] [Help] An endiian problem in telosb motes that use MSP430

Michael Schippling schip at santafe.edu
Mon Dec 18 12:50:06 PST 2006


This is a weird one...it looks at first blush that it should work.
I would try a couple things to see what's what.

First use different 2 byte values for all your fields and then
do a byte by byte dump of the memory around the struct to see
what is really getting set where. You could also look at the
address of each field to see where they are being placed.

Second, instead of doing the sizeof() indexing, try:
	pPos = (POS*) &tmp.b;
My belief is that casts take precedence over arithmetic
but the compiler may not agree...

MS

Hejun Wu wrote:
> Hi,
>  
> I am using telosb motes and I think that there is a problem of the 
> MSP430 compiler:  
>  
> Suppose we have the following program:
>  
> typedef struct {int a; int b; int c;}TMP;  
> typedef struct {int x; int y;}POS;
> TMP tmp;
> POS * pPos;
> tmp.a = 1;
> tmp.b = 1;
> tmp.c = 1;
> pPos = (POS*) ((char*)&tmp + sizeof(int));
>  
> pPos->x = 1;
>  
> Then, the value of pPos->y will be 0x0100, but pPos->x will be 0x0001 
> (lower byte of pPos->x is 0x01 and the higher byte is 0x00). 
>  
> How can I fix this problem?  Thanks!
>  
> Best regards,
> Hejun
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help at Millennium.Berkeley.EDU
> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help


More information about the Tinyos-help mailing list