I'm reading the book "Palm OS Programming Bible" Chatper 10. I met some
question on the following routine. I've studied it again and again but I
don't know what missed.

Here is the question:
(A) 'packed' is declared as pointer to LibPackedDBRecord. Why it can be used
after just initialization to zero? Also, the fields of structure can be
accessed without assignment of address of structure to it. I'm confused.

Welcome to any advice.

======================== type definition in concern

typedef struct {
    LibStatusType status;
    LibDBRecordFlags flags;
    unsigned char lastNameOffset;
    unsigned char firstNameOffset;
    unsigned char yearOffset;
    unsigned char noteOffset;
    char firstField;
} LibPackedDBRecord;

======================== routine with question

static void PackRecord( LibDBRecordType *record, MemPtr recordDBEntry )
{
    UInt32 offset;
    Int16 index;
    UInt16 length;
    MemPtr p;
    LibDBRecordFlags flags;
    LibPackedDBRecord *packed=0;   <------------ (A)
    Char lastNameOffset=0, firstNameOffset=0,
        yearOffset=0, noteOffset=0;

    flags.allBits = 0;

    DmWrite( recordDBEntry, (UInt32) &packed->status,  <---------
        &record->status, sizeof( record->status ));
    offset = (UInt32)&packed->firstField;

    for (index=0; index<libFieldsCount; index++) {
        if (record->fields[index] != NULL ) {
            p = record->fields[index];
            length = StrLen(p) + 1;

            DmWrite( recordDBEntry, offset, p, length );
            offset += length;
            SetBitMacro( flags.allBits, index);
        }
    }
    .
    . <----- no 'packed' variable appears in-between
    .
    DmWrite( recordDBEntry, (UInt32)(&packed->lastNameOffset),  <-------
        &lastNameOffset, sizeof( lastNameOffset));
    DmWrite( recordDBEntry, (UInt32)(&packed->firstNameOffset),  <-------
        &firstNameOffset, sizeof(firstNameOffset));
    DmWrite( recordDBEntry, (UInt32)(&packed->yearOffset),  <-------
        &yearOffset, sizeof( yearOffset));
    DmWrite( recordDBEntry, (UInt32)(&packed->noteOffset),   <-------
        &noteOffset, sizeof(noteOffset));
}

========================



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

Reply via email to