if you increment a pointer then it increments the size of the pointer. ie.

char *a = 0x0000
a++       // a= 0x0001

int *a = 0x000
a++     // a = 0x0002 (16 bit ints)

long *a=0x000
a++   // a = 0x0004

similarly if you have a structure x which is 20 bytes

struct x *ptr
ptr = 0x0000
ptr++   //ptr = 0x0020

Also if you cast the Void * to a pointer to you structure type, you can
access your data struct_pointer->field.

The reason you cant add stuff to a Void * is that the complier dont know how
much to add. If you cast it, then the above rules apply.

It looks like you want to use stuctures and pointers to structures for your
problem

Rik

> -----Original Message-----
> From: Jacob Vitas Vogelstein [SMTP:[EMAIL PROTECTED]]
> Sent: 25 September 2000 15:01
> To:   Palm Developer Forum
> Subject:      Which pointer type to use when accessing a record?
> 
> This question stems from my general inexperience with the C programming
> language... I'll state the question first, then my example code. After I
> get
> a record handle with DmQueryRecord, I lock it down and get a VoidPtr from
> MemHandleLock. This pointer points to the start of my record in the
> database, and I want to access the second field of the database, in my
> case,
> at an offset of sizeof(WChar). But when I try to access that field by
> saying: *(myPtr + myOffset), the compiler complains that it can't add
> anything to a VoidPtr type. So I have to cast it as something. Depending
> on
> how I cast it, I get different values returned to me for both the *(myPtr)
> variable and the (*myPtr + myOffset) variable. Since I may have many
> different types of data in my database, what's the right way to cast the
> pointer to correctly access the variables? Thanks for your help. Code
> follows.
> 
> 
> I defined the properties of a record in my database like this:
> 
> #define DB_PEN_DOWN_START 0
> #define DB_PEN_DOWN_SIZE sizeof(WChar)
> #define DB_PEN_UP_START (DB_PEN_DOWN_START + DB_PEN_DOWN_SIZE)
> #define DB_PEN_UP_SIZE sizeof(WChar)
> #define DB_PENSTROKE_RECORD_SIZE (DB_PEN_DOWN_SIZE + DB_PEN_UP_SIZE)
> 
> 
> And now I want to access the information. So I call:
> 
> VoidHand hrecord;
> VoidPtr precord;
> cursor = 0;
> hrecord = DmQueryRecord( prevAppHackDB, cursor );
> precord = MemHandleLock( hrecord );
> 
> 
> And finally, I want to write the value of the record into two fields on my
> form, using a home-made function called 'StrToField' that takes the name
> of
> the field, the size of the data to write, and the data itself as
> parameters.
> 
> WChar temp;
> char tempstr[10];
> temp = *((WCharPtr)precord + DB_PEN_DOWN_START);  // DB_PEN_DOWN_START = 0
> StrIToH(tempstr, temp);
> StrToField(ControlPanelFormStartBtnField, sizeof(tempstr), tempstr); //
> RETURNS THE RIGHT THING
> temp = *((WCharPtr)precord + DB_PEN_UP_START); // DB_PEN_UP_START =
> sizeof(WChar)
> StrIToH(tempstr, temp);
> StrToField(ControlPanelFormEndBtnField, sizeof(tempstr), tempstr); //
> RETURNS THE WRONG THING
> 
> MemHandleUnlock(hrecord);
> 
> 
> 
> -- 
> 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