I figured out how to eliminate the database shifting that happened  when I
migrated my application from GCC to CW.

I wrote my original GCC program using the following structure, and it always
worked
fine.
 typedef struct
 {
   unsigned             selected                : 1;
   unsigned             itemtype                : 1;
   unsigned             hidden                  : 1;
   unsigned             sublistID               : 5;
   Byte         bListID;
   UInt         uiNumMaster;
 }  PackedList;

When I compiled the above code with CW and ran it, it looked like my data
was being shifted by one or two bytes and the shift got progressively worse
the further along in the data I went.

I fixed the problem in CW by changing the type from 'unsigned' to 'UChar' so
the structure looked like this.
 typedef struct
 {
   UChar                selected                : 1;
   UChar                itemtype                : 1;
   UChar                hidden                  : 1;
   UChar                sublistID               : 5;
   Byte         bListID;
   UInt         uiNumMaster;
 }  PackedList;

Now everything lines up!

It looks like GCC compiled my 'unsigned' bit fields into one byte; CW was
using two bytes. By explicitly telling CW to use one byte by using UChar,
the database shifting went away.

Mitch Fawcett
Tapn'see Software
Home of SuperList2
http://www.tapnsee.com



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of John
Marshall
Sent: Sunday, July 23, 2000 11:03 AM
To: Palm Developer Forum
Subject: Re: Database is shifted


Mitch_Fawcett <[EMAIL PROTECTED]> wrote:
> I'm not ruling out a program
> bug, but is there an alignment issue in going from GCC to CW that could be
> the cause?

Uh huh: CodeWarrior is broken.  If you run some sizeof() and offsetof()
tests on your struct on the two compilers, you'll see that CW hasn't
put your `bListID' field where you expect it to, and then the rest of
your struct is out of whack too.

The last few times I attempted to summarise the differences were in the
following messages, but I don't think I had it quite right.  Certainly the
sum-to-16-bits rule is right, though.

        news://news.massena.com/#B21jpod$[EMAIL PROTECTED]
        news://news.massena.com/jdweHqlp$[EMAIL PROTECTED]

    John

--
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