Jannick said:
Sorry to post defective code....I was to quick in cutting the problem out of
entire code... I think it is my compiler tricking me :-(, the "unsigned int*
sram_location = (unsigned int *) 0xFF120011" is okay because the code is
intended for a microcontroller that has a peripheral device memory-mapped at
this location.
I solved the problem though, but do still not understand it...I think the
error lies in the compiler and dont think the error is easily seen. When I
did:
*sram_location = ( ((measuredata.n1.number1)<<24) | (
(measuredata.n1.number2)<<16) | ( (measuredata.n2.number3)>>16) );
I got the 0x1A000000
When I do the:
*sram_location = (
((measuredata.n1.number1<<16)<<8) | ((measuredata.n1.number2)<<16) | (
(measuredata.n2.number3) >>16) );
I get the correct result: 0x34000000
Dont ask me why......
The only difference (which would have been a lot clearer if you had
formatted and indented the code more clearly) is the change from
(measuredata.n1.number1)<<24
to
(measuredata.n1.number1<<16)<<8
What happens when you display the values of those expressions in
isolation? What are the types of number1, number2, number3, and
*sram_location? What is the size of int on your platform?
If number1 is an unsigned int, and unsigned int is 16 bits on your
platform, you could be seeing undefined behavior because the right
operand of the "<<" is greater than or equal to the size of the
operand. If this is the problem, and you're trying to get an unsigned
long result (at least 32 bits), you should cast each operand to unsigned
long before shifting it:
*sram_location =
( (unsigned long)measuredata.n1.number1 << 24 ) |
( (unsigned long)measuredata.n1.number2 << 16 ) |
( (unsigned long)measuredata.n2.number3 >> 16 );
(On the other hand, if number3 is 16 bits, it doesn't make much sense
to do a 16-bit right shift on it.)