|
From: | Wallace White |
Subject: | Re: [avr-gcc-list] Time-efficient read of high byte in two-byte variable |
Date: | Thu, 08 May 2003 15:59:11 -0700 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3.1) Gecko/20030425 |
E. Weddington wrote:
There's been a lot of discussion and it seems the most efficient way is to use a union.#include <inttypes.h> typedef struct { unsigned char lo; unsigned char hi; } hilow_t; typedef union { uint16_t word; hilow_t byte; } mytype ; mytype encPosDetentsNow; ... { ....encPosDetentsNow.word = 0xFFFF; UDR = encPosDetentsNow.byte.hi;.... } See what you get with this.
That indeed works well. Cool.Let's see, my variable in question is a signed int... so I could change the typedef union
typedef union { int16_t word; hilow_t byte; } mytype ;and tack on .word to all my references to that variable... that should be fine, right?
Thanks, Wallace
[Prev in Thread] | Current Thread | [Next in Thread] |