Thanks a bunch. In fact, my data is declared as a C struct. I was trying
to avoid copying the data from my Rec to my structure. Your idea of
using a pointer to a structure is great.
Since my compare function will be passed pointers to the record data, they
are already pointers to my struct. All I have to do is make declare the
compare functions to accept pointers to struct.
Nice tip.
On Mon, 22 Mar 1999, Jim Schram wrote:
> At 2:29 PM -0800 1999/03/22, Michael S. Davis wrote:
> >Ok, almost got it. Let's say my compare functions performs
> >as follows:
> >
> >double elem1 // variables within a record
> >double elem2 // variables within a record
> >
> >if(elem1 < elem2){ return -1 };
> >if(elem1 == elem2){ return 0 };
> >if(elem1 > elem2){ return +1 };
> >
> >Now my problem is this. this is easy if I declare elem1 and elem2
> >but how do I refer to these as part of the record.
>
> Assuming fixed-sized fields in your records (which allows you to declare the record
>as a C struct) just declare the first two 'void *' pointers as pointers to your
>record struct type and defererence the appropriate member using the -> notation, like
>this:
>
> typedef struct MyDBStruct { // hypothetical fix-sized data record
> char str1[50];
> double num1
> char str2[25];
> short num2;
> } MyDBStruct;
>
> typedef MyDBStruct* MyDBStructPtr;
>
> Int MyCompareFunc( MyDBStructPtr p1, MyDBStructPtr p2, ...)
> ...
> if ( p1->num1 < p2->num1 ) return -1;
> etc.
>
>
> Regards,
>
> Jim Schram
> 3Com/Palm Computing
> Partner Engineering
>
>
----------------------------------------------------
Shoot-to-Win
Protect the 2nd Amendment
----------------------------------------------------