Hi all I have a strange problem when I'm trying to cast buffers by arm compiler. Here an example:
char* pbuf; ... unsigned short val = *((unsigned short*)(pbuf+3));
When I compile this code, my generated assembly code uses LDRH,STRH. Then because my pbuf+3 is not multiple of 2 and those 2 instruction can only work with even value addresses, processor hangs up. What I should to do that compiler generates a code that works in all cases?
Regards
"And not portable, as you well know, Sausage man."
It is not ***guaranteed*** to be portable. There is a (subtle) difference.
The projects on which I've used it were on 51s, Z80s, V55, 186s, 386s. No problems with portability of the relevant modules there.
It made data manipulation and storage far more efficient.
I'm now porting code to the ARM. Looked into using the __packed keyword, but probably won't use it because ARM has such extreme raw processing power.
The key to this, like nearly every other embedded task, is a thorough understanding of the low level operation of the processors.