Bit-packing (physical) order is implementation dependant. Thus, you should
not assume any order nor should you assume that anything other than (native
type) int can be bit-packed "safely." Use bitmasks and bitflags rather than
bit fields:
typedef struct {
Word wYYMMDD;
void SetYear(Word wYear)
{
wYYMMDD = (wYYMMDD & 0x01FF) | (wYear << 9);
}
} DateType;
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Chris
Faherty
Sent: Friday, May 19, 2000 3:52 PM
To: Palm Developer Forum
Subject: Bit packing and endianess
I'm porting some of my palmos code over to a little-endian device (RIM950).
It uses the MS Visual C++ compiler for the SDK. The problem I am having is
with structures that use bit packing:
typedef struct {
Word year :7;
Word month :4;
Word day :5;
} DateType;
On Codewarrior and GCC the bits are packed starting with msb. In VC++ they
start at lsb. So in VC++ I have to use:
typedef struct {
Word day :5;
Word month :4;
Word year :7;
} DateType;
I realize that Word (an unsigned short) is LSB versus MSB and though I
already take that into account, the position of the bit components is
opposite. For example on the palm compilers year is the most significant 7
bits of the Word, but in VC++ (using the top structure) year is the least
significant 7 bits.
Just wondering if there is a compiler directive to tell VC++ to pack those
bits starting at the msb. It doesn't really seem like an endianess issue
but
rather a compiler preference issue.
/* Chris Faherty <[EMAIL PROTECTED]> */
/* Your Stock has crashed - you must now restart your system */
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/