le 6/06/03 2:26, Jeff Ishaq � [EMAIL PROTECTED] a �crit�:

> I need to read raw data from a OS preference resource.  On OS4 machines,
> it's simply a matter of locking down the returned resource handle and
> casting it to the appropriate OS-defined structure pointer.  However, on
> OS5, ARM alignment and byte ordering take effect, so it becomes more
> difficult.
> 
> I have learned so far:
> 
> 1) You must byte-swap 16-bit and 32-bit values
> 2) ARM enforces DWord alignment
> 
> I understand and can do #1, no problem.  I can't wrap my head around "DWord
> alignment", however.  Does this mean that any value that is smaller than a
> 32 bits ALWAYS becomes padded with enough zeros to make it 32 bits?  So
> this structure:
> 
> struct {
> UInt8  byVal1;
> UInt8  byVal2;
> UInt8  byVal3;
> }
> 
> would occupy 32 + 32 + 32 bits?
> 
> Or does the compiler just pad an extra 8 bits to the structure?  Exactly
> where do these extra bits go?  What if we had:
> 
> struct {
> UInt8 byVal1;
> UInt8 byVal2;
> UInt8 byVal3;
> UInt16 wVal4;
> UInt8 byVal5;
> }
> 
> Is there some online reference manual or FAQ somewhere that might lay down
> the law for this?  I would very much appreciate it!
> 
> Thanks,
> -Jeff
> 

ARM processors need 4 byte algnment for any value larger than 1 byte.

So
 struct {
> UInt8  byVal1;
> UInt8  byVal2;
> UInt8  byVal3;
> }

Is 3 bytes

 struct {
> UInt8 byVal1;
> UInt8 byVal2;
> UInt8 byVal3;
> UInt16 wVal4;
> UInt8 byVal5;
> }

Requires padding after byVal3, and is 7 bytes

You need to tell the compiler to align on 4 bytes and/or do the padding by
hand (which is safer)

-------------------------------
Eric VERGNAUD - JLynx Software
Cutting-edge technologies and
services for software companies
web: http://www.jlynx.com
-------------------------------


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

Reply via email to