about the storageof variables (arm7 platform)

来源:互联网 发布:如何关闭qq游戏端口 编辑:程序博客网 时间:2024/04/30 15:04

In this screen, we can see the storage of variable NvSt_InfoB.u8_PumpDuty,

It is a byte value which has 8bits, I want to change its value in a routine, so I transfer its address into the routine, but the address used by the routine should be int32, so I force it address to int32 by do this: (INT32U*)&NvSt_InfoB.u8_PumpDuty.

All of the process done are still right, but later its problem coming. When I get the value which stored in the 32 bits address, it get the  value of

u8_PumpDrv[0](0)

u16_PumpCycle(110:0x6E)

NvSt_InfoB.u8_PumpDuty(50:0x32)

 

So the value is 6E32 (28210)

 

Form doing this we can know two things

what the internal process of a forceful variable type change?

Answer: it will extend the higher address, and lower address store the low byte value.

So now we used little-ended.

 

Attention: you can forceful change a variable from Int8 to Int32

,but if you want to forceful change a pointer from Int8* to Int32* you need to know that the value store in the Int32* address maybe different, its value related with the 24bits value near the 8bits address, if these 24bits not 0 , you will get a wrong value finally!

强制类型转换在变量中可能好用,但在转化指针时就要注意了,这个转换后的地址取出的值可比转换前的长或者短,这就出问题了。