What you are doing is *compiler* dependant, not *platform* dependant. You might
want to check for compiler-specific conditionals instead.

Or avoid the whole problem and just do it by hand, as Al Cilcius suggests. It's
uglier, but more portable.

-- Keith






"Mike Margerum" <[EMAIL PROTECTED]> on 05/19/2000 01:26:04 PM

Please respond to "Palm Developer Forum" <[EMAIL PROTECTED]>

Sent by:  "Mike Margerum" <[EMAIL PROTECTED]>


To:   "Palm Developer Forum" <[EMAIL PROTECTED]>
cc:    (Keith Rollin/HQ/3Com)
Subject:  Re: Bit packing and endianess



I just conditionally compile the struct based on whether its for windows or
the palm:
#ifdef WIN32
typedef struct {
     Word day   :5;
     Word month :4;
     Word year  :7;
} DateType;
#else
typedef struct {
    Word year  :7;
    Word month :4;
    Word day   :5;
} DateType;
#endif
----- Original Message -----
From: "Chris Faherty" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Friday, May 19, 2000 3:51 PM
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/






-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to