Richard Hartman wrote:
> Yes, it is all transparent to you -unless- you
> start trying to calculate offets from a void *,
> in which case you must be aware of the padding
> issues.

To calculate struct member offsets, use the offsetof macro:

  #define offsetof(type, member) \
          ((unsigned int) &(((type *) 0)->member))

This macro in in <stddef.h> in the Metrowerks library; just paste it
into a convenient header for use in a Palm project.

This macro will always return the correct offset value, such as for
using DmWrite to write a single field of a struct located in storage
memory.  It forces the compiler to do all the math including accounting
for any padding in the struct.  Very handy.

Basically my rule is: if you find yourself doing any math yourself to
figure out sizes or offsets, then you're probably doing something wrong
and should look for a way to make the compiler do the work.  That's what
sizeof and offsetof (and countof, for arrays) are for.

-slj-

Reply via email to