Portability Issues

There are two important portability issues to take into account when moving data back and forth from the handheld to the desktop: byte ordering and structure packing.

Byte Ordering

The Palm OS currently runs on a Motorola platform, which stores bytes differently from Windows running on an Intel platform. This crucial difference can mess up data transfers royally if you are not careful.

Tip

It’s been announced that a future version of the OS will run on the ARM processor in little-endian mode (which will match the Intel ordering). Right now, it’s not clear what the implication will be for conduits. To be safe, use the Sync Manager routines for swapping rather than writing your own.

On the handheld, the 16-bit number 0x0102 is stored with the high byte, 0x01, first, and the low byte, 0x02, second. In the conduit on Windows, the same number is stored with the low byte, 0x02, first, and the high byte, 0x01, second. As a result, any 2-byte values stored in your records or in your AppInfo block must be swapped when transferred between the two systems. (If you fail to swap, a simple request for 3 boxes of toys on the handheld would be processed on the desktop as a request for 768 boxes!) A similar problem occurs with 4-byte values; they are also stored in switched forms (see Table 15-2).

Table 15-2. Comparison of byte orderings for the 4-byte value 0x01020304

Palm handheld byte order

Wintel byte order

0x01
0x04
0x02
0x03
0x03
0x02
0x04
0x01

The Sync Manager ...

Get Palm OS Programming, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.