Rick,

If "pointer" == NULL, then "pointer->next" attempts to fetch the value of the
"next" field in the StandardDataDelement stored at memory location zero. Since
there is no StandardDataDelement  at that memory location, this is not what you
want to do. You are merely trying to get the *offset* of the "next" field. To do
this, use the offsetof macro:

     DmWrite (myRecPtr, offsetof (StandardDataElement, next), &data, sizeof
(data);

Please also note that I changed the "1" in your example with the more
descriptive "sizeof (data)".

The offsetof macro is defined in <stddef.h>, generally along the lines of:

     #define offsetof(s,m)   (size_t)&(((s *)0)->m)

-- Keith Rollin
-- Palm OS Emulator engineer






Richard Bram <[EMAIL PROTECTED]> on 07/11/99 09:29:12 PM

Please respond to [EMAIL PROTECTED]

Sent by:  Richard Bram <[EMAIL PROTECTED]>


To:   [EMAIL PROTECTED]
cc:    (Keith Rollin/HQ/3Com)
Subject:  DmWrite problem in POSE




What's the best way to refer to offsets within a
record? I have a struct which I want to write to
a storage record, sort of like this:

typedef struct
{
     Byte next;
     etc....
} StandardDataElement, *StandardDataPtr;

To write it to a record, I used to make a StandardDataPtr  pointer,
and make it = 0. Then I used to do:


DmWrite(myRecPtr,(ULong) pointer->next,&data,1);

While this usually works on the device, it seems to crash the emulator.
I get a error about reading from low memory. If, instead, I use:


DmWrite(myRecPtr,0,&data,1);

it seems to work fine. So if we aren't allowed to use a zero pointer
to get the offsets, how else can one do this?

Thanks ,

Rick Bram








Reply via email to