??? 03/31/10 16:33 Read: times Msg Score: +1 +1 Informative |
#174685 - unions and portability Responding to: ???'s previous message |
Andy Neil said:
Things like byte ordering and whether or not padding is added are compiler-specific - so this is not portable! Indeed. I'm working on a little stepper-motor controller, and I'm using the Silicon Labs app note (AN155) as a reference. The SiLabs code uses a union to store a 16-bit value as either a 16-bit word or a pair of bytes (upper and lower). This union holds a 16-bit value which is used to initialize a timer. So the idea is to add some new offset to the timer value. The timer value is read into the two bytes (two MOVs essentially) and then the offset is added to the 16-bit word, then the two bytes are written back to the timer (two more MOVs). Keil is big-endian. SDCC is little-endian. I'm not using the union. -a |